0

假设您有一个 AngularJS 指令,您希望在其中将控制器属性和controllerAs属性设置为相同的字符串。

前任。

angular.module('blahModule', [])
.directive('blahDirective', function(){
    return {
        restrict: 'E',
        controller: 'blahController',
        controllerAs: 'blahController',
        templateUrl: 'blah/blah.html'
    }
});

以上是有效的并且有效,但是当将控制器控制器的值设置为相同的东西时感觉是多余的。有没有办法在一个属性中做到这一点?喜欢:

angular.module('blahModule', [])
.directive('blahDirective', function(){
    return {
        restrict: 'E',
        controllerAndControllerAs: 'blahController',
        templateUrl: 'blah/blah.html'
    }
});

提前致谢!

4

1 回答 1

1

您可以使用

controller: 'blahController as blahController',
于 2015-10-23T19:27:21.857 回答