相关疑难解决方法(0)

Angularjs缩小了最佳实践

我正在阅读 http://www.alexrothenberg.com/2013/02/11/the-magic-behind-angularjs-dependency-injection.html,结果发现如果你缩小你的javascript,angularjs依赖注入有问题,所以我我想知道是否代替

var MyController = function($scope, $http) {
    $http.get('https://api.github.com/repos/angular/angular.js/commits')
      .then(function(response) {
        $scope.commits = response.data
      })
  }
Run Code Online (Sandbox Code Playgroud)

你应该使用

var MyController = ['$scope', '$http', function($scope, $http) {
  $http.get('https://api.github.com/repos/angular/angular.js/commits')
    .then(function(response) {
      $scope.commits = response.data
    })
}]
Run Code Online (Sandbox Code Playgroud)

总而言之,我认为第二个片段是旧版本的angularjs,但....

我应该总是使用注入方式(第二个)吗?

javascript dependency-injection angularjs

100
推荐指数
4
解决办法
9万
查看次数