Angularjs 理解为什么$http会传入angular.js控制器
我刚刚在这里浏览了angular.js教程,基本上教程中构建了以下脚本:Angularjs 理解为什么$http会传入angular.js控制器,angularjs,Angularjs,我刚刚在这里浏览了angular.js教程,基本上教程中构建了以下脚本: angular.module('APP',[]). controller('theController' , ['$scope' , '$http' , function( $scope , $http ){ $http.jsonp('http://www.filltext.com/?rows=30&id={index}&fname={firstNam
angular.module('APP',[]).
controller('theController' , ['$scope' , '$http' , function( $scope , $http ){
$http.jsonp('http://www.filltext.com/?rows=30&id={index}&fname={firstName}&lname={lastName}&sales={randomNumberRange|100to2000}&bonus={randomNumberRange|200to600}&callback=JSON_CALLBACK').success(function(data){
$scope.users = data
});
$scope.totalMoney = function(user) {
return user.sales + user.bonus;
}
}]).filter('initials' , function(){
return function(text){
var names = text.split(' '),
holder = [];
angular.forEach(names , function(item){
holder.push(item.substring(0,1) + '.');
});
return holder.join('');
}
});
,tut实际上是关于如何创建自定义过滤器的,这已经解释得很清楚了。但是我不太明白传递进来的
“$http”
,有人能解释一下吗 我猜你在试图理解“注射”的概念。这里有一个关于细节的教程:
但是,简而言之。在Angular执行大多数方法之前,它会扫描它们以查看它们在寻找什么,然后按照预期的顺序将这些参数传递给该方法
通常在javascript中,您必须知道传入的顺序参数,然后相应地命名它们。但对于角度,它是相反的。它预测你的要求,并给你你想要的
所使用的数组格式称为“依赖项注释”,是一种特定于角度的格式。它只是在那里使缩小工作。在不缩小的情况下,您可以执行以下操作,它也可以工作:
angular.module('APP',[]).
controller('theController', function($scope , $http){
$http.jsonp('http://www.filltext.com/?rows=30&id={index}&fname={firstName}&lname={lastName}&sales={randomNumberRange|100to2000}&bonus={randomNumberRange|200to600}&callback=JSON_CALLBACK').success(function(data){
$scope.users = data
});
$scope.totalMoney = function(user) {
return user.sales + user.bonus;
}
}).filter('initials' , function(){
return function(text){
var names = text.split(' '),
holder = [];
angular.forEach(names , function(item){
holder.push(item.substring(0,1) + '.');
});
return holder.join('');
}
});
它被传了进来,因为它被用于controller@kodvin我已经完全知道了!!角度中的
$scope
和$http
是什么??这些是什么东西
我建议做一次调查来涵盖一些核心概念。另外,搜索Angular文档,它非常有用。并且有很好的记录