2014-10-18 73 views
-1

我想定義一個控制器在一個抽象的狀態,以便我可以有一個單一的控制器爲我所有的意見,但控制器內的功能不會被調用,如果控制器是外面定義。在一個狀態視圖控制器

.state('update', { 
     url : '/update', 
     abstract: true, 
     template: '<ui-view/>', 
     controller : function($scope) { //works 
      $scope.hello = function() { 
       alert("hello"); 
      } 
     } 
     controller : 'updateController' // Doesn't work 
    }) 
    .state('update.detail', { 
     url : '/view/:id', 
     views : { 
      "" : { 
       templateUrl : 'update-detail.html' 
      }, 

      "[email protected]" : { 
       templateUrl : 'header.html' 
      }, 
      "[email protected]" : { 
       templateUrl : 'generic-navigation.html' 
      }, 
      "[email protected]" : { 
       templateUrl : 'mobile-navigation.html' 
      }, 
      "[email protected]" : { 
       templateUrl : 'update-content.html' 
      } 
     } 
    }) 

HTML

header.html 
<div ng-click="hello();"></div> //Click event doesn't get fired for (controller : 'updateController') 


app.controller('updateController', ['$scope', '$state', function($state, $scope) { 
console.log("inside update") 
$scope.hello = function() { 
     alert("hello"); 
} 
}]); 

回答

0

看你如何定義你的控制器:

['$scope', '$state', function($state, $scope) 

的參數是不正確的順序。所以$ state變量實際上是範圍,而$ scope變量實際上是狀態。

+0

非常感謝它的工作 – user1184100 2014-10-18 11:25:27

相關問題