AngularJS:在指令发出微小 [英] AngularJS : minification issue in directive
问题描述
我有一个微小的又一问题。这一次,这是因为通过该指令的控制器$范围的服务。请参见下面code:
I have yet another issue with minification. This time it's because of the $scope service passed to the directive's controller. See below code:
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;
}
}
}]);
如果我注释掉控制器部分,那么它工作正常。
If I comment out the controller part, then it works fine.
正如你所看到的,我使用的指令数组声明,所以$对话服务,即使微小后已知角。但是,我怎么办呢控制器上的$范围的服务?
As you can see, I've used the array declaration for the directive, so the $dialog service is known to Angular even after minification. But how am I supposed to do it for the $scope service on the controller ?
推荐答案
您需要声明一个控制器如下:
You need to declare a controller as follows:
controller: ['$scope', function ($scope)
{
$scope.test = 3;
}]
在这里完整的示例:
Full example here:
angular.module('person.directives').
directive("person", ['$dialog', function($dialog) {
return {
restrict: "E",
templateUrl: "person/views/person.html",
replace: true,
scope: {
myPerson: '='
},
controller: ['$scope', function ($scope)
{
$scope.test = 3;
}]
}
}]);
由@Sam提供了一个解决方案,将努力但这意味着指令的控制器暴露整个应用程序,它是不必要的。
A solution provided by @Sam would work to but it would mean exposing directive's controller to the whole application which is unnecessary.
这篇关于AngularJS:在指令发出微小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!