我还有另一个关于缩小的问题。这一次是因为$ scope服务传递给指令的控制器。见下面的代码:
- angular.module('person.directives').
- directive("person",['$dialog',function($dialog) {
- return {
- restrict: "E",templateUrl: "person/views/person.html",replace: true,scope: {
- myPerson: '='
- },controller: function ($scope)
- {
- $scope.test = 3;
- }
- }
- }]);
如果我注释掉控制器部分,那么它工作正常。
正如你所看到的,我已经使用了指令的数组声明,所以即使在缩小后,$对话框服务也是已知的。但是我应该怎么做的控制器上的$ scope服务呢?
您需要声明控制器如下:
- controller: ['$scope',function ($scope)
- {
- $scope.test = 3;
- }]
完整示例:
- angular.module('person.directives').
- directive("person",controller: ['$scope',function ($scope)
- {
- $scope.test = 3;
- }]
- }
- }]);
@Sam提供的解决方案将工作,但它将意味着将指令的控制器暴露于整个应用程序是不必要的。