我编写了一个相当简单的指令,可以动态更改页面上的样式表。
这是指令的一个片段:
OfficeSuiteModule.directive('officeButton', ['$q', 'stylesheetInjectorService', function($q, stylesheetInjectorService) {
return {
restrict: 'E',
replace: true,
scope: {
isDisabled: '@?',
label: '@?',
api: '='
},
template: OFFICE_BUTTON_TEMPLATE,
// Defines the controller for the 'officeButton' directive.
controller: function($scope) { }
}
}]);
现在,我正在使用 grunt 来构建我的项目,并且正在使用任务 grunt-contrib-uglify
来缩小 JavaScript 文件,但是我在这里遇到了一个问题。
如果我查看 JavaScript 文件的缩小版本,指令签名中的 Controller 将更改为:controller: function(c) {}
因为 c
没有定义,所以这不会起作用。它会引发 AngularJS 错误。
是否有 Angular 方法来解决这个问题,或者我可以指示 grunt-contrib-uglify 任务不要更改此参数?
亲切的问候
最佳答案
你也必须注释 Controller 函数:
controller: ['$scope', function($scope) {
// your function
}]
因此您的完整代码变为:
OfficeSuiteModule.directive('officeButton', ['$q', 'stylesheetInjectorService', function($q, stylesheetInjectorService) {
return {
restrict: 'E',
replace: true,
scope: {
isDisabled: '@?',
label: '@?',
api: '='
},
template: OFFICE_BUTTON_TEMPLATE,
// Defines the controller for the 'officeButton' directive.
controller: ['$scope', function($scope) {
// your function
}]
}
}]);
关于javascript - 如何防止 grunt-uglify 混淆指令中的 angularJS 范围值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31557671/