2014-10-18 71 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

相关问题