我试图通过函数在控制器属性中输入一个值。 做这样的事情:
.state('integrator.optionCommandTabContent', {
url: '/integrator/optionCommandTabContent/:optionId/:ctrlName',
views: {
'optionConfigTabContent@': {
templateUrl: '../../../angular-app/components/integrator/integrator-conf/option-conf/commands-tab/command-tab.html',
controller: function ($stateParams){
return $stateParams.ctrlName.toString();
},
controllerAs: 'ctrl',
resolve: {
optionId: function($stateParams){
return $stateParams.optionId;
}
}
}
}
});
似乎控制器属性没有获得函数的返回值。可以用另一种方式做这样的事情吗?
答案 0 :(得分:0)
controller
不应返回任何内容。它应该提供动作并做一些初始化和破坏东西。例如。
controller: function ($stateParams, $scope, someService){
// naive sync init
this.items = someService.load($sateParams.id);
// example of action
this.edit = function(item) {
...
}
// destroy on view leave
$scope.$on('$on', function(){
...
});
},
可以在您的视图中使用
<li ng-repeat="item in ctrl.items"> ...
<button ng-click="ctrl.edit(item) ...