加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – ngInject在下面的代码中做了什么?

发布时间:2020-12-17 07:18:42 所属栏目:安全 来源:网络整理
导读: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: '/r
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',title: 'Sign up'
  });

};

export default AuthConfig;

我无法弄清楚ngInject的用途.有人可以帮帮我吗?

‘ngInject’;什么都不做,它只是一个字符串文字.名为ng-annotate的工具使用它作为标志:如果函数以’ngInject’开头,则它将由ng-annotate处理.

基本上,ng-annotate将会改变

angular.module("MyMod").controller("MyCtrl",function($scope,$timeout) {
    "ngInject";
    ...
});

angular.module("MyMod").controller("MyCtrl",["$scope","$timeout",$timeout) {
    "ngInject";
    ...
}]);

为了使代码缩小安全.

如果您没有使用ng-annotate,则可以安全地忽略或删除表达式.但要小心,如果项目使用ng-annotate,您可能会破坏项目的构建过程.
有关ng-annotate及其功能的更多信息,请参阅https://github.com/olov/ng-annotate

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读