我正在阅读 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,但....
我应该总是使用注入方式(第二个)吗?
我已经看了三种不同的方法来缩小AngularJS脚本.但是,它们都没有解释我应该如何考虑自定义过滤器.我的代码格式如下:
app.controller("App", ["$scope","$timeout", function($scope, $timeout){...}]);
Run Code Online (Sandbox Code Playgroud)
除了一些像这样的附加代码:
app.filter('unsafe', function($sce) {
return function(val) {
return $sce.trustAsHtml(val);
};
});
Run Code Online (Sandbox Code Playgroud)
当我缩小以上所有内容时,不再识别过滤器.我如何准备我的代码进行缩小?