AngularJS控制器代码:
function AuthConfig($stateProvider, $httpProvider) {
'ngInject';
// Define the routes
$stateProvider
.state('app.login', {
url: '/login',
templateUrl: 'auth/auth.html',
title: 'Sign in'
})
.state('app.register', {
url: '/register',
templateUrl: 'auth/auth.html',
title: 'Sign up'
});
};
export default AuthConfig;
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚ngInject的用途.有人可以帮帮我吗?
Wir*_*iwi 29
'ngInject';什么都不做,它只是一个字符串文字.一个名为ng-annotate的工具使用它作为标志:如果函数以一个函数开头'ngInject';,它将由ng-annotate处理.
基本上,ng-annotate将会改变
angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) {
"ngInject";
...
});
Run Code Online (Sandbox Code Playgroud)
至
angular.module("MyMod").controller("MyCtrl", ["$scope", "$timeout", function($scope, $timeout) {
"ngInject";
...
}]);
Run Code Online (Sandbox Code Playgroud)
为了使代码缩小安全.
如果您没有使用ng-annotate,则可以安全地忽略或删除表达式.但要小心,如果项目使用ng-annotate,您可能会破坏项目的构建过程.有关ng-annotate及其功能的更多信息,请参阅https://github.com/olov/ng-annotate
| 归档时间: |
|
| 查看次数: |
8501 次 |
| 最近记录: |