Javascript 如何让这个对象以AngularJS打印出来?
我目前正在angularJS的一个项目中工作,我正在仔细研究我们的系统是如何工作的,但不管出于什么原因,新的回报没有显示在angularJS中。。 下面是我的html的外观Javascript 如何让这个对象以AngularJS打印出来?,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我目前正在angularJS的一个项目中工作,我正在仔细研究我们的系统是如何工作的,但不管出于什么原因,新的回报没有显示在angularJS中。。 下面是我的html的外观 <button ng-repeat="company in companies" ng-click="setCompany(company)"> {{ company.name }} </button> 但无论出于什么原因,它都不会打印出具有以
<button ng-repeat="company in companies" ng-click="setCompany(company)">
{{ company.name }}
</button>
但无论出于什么原因,它都不会打印出具有以下结构的对象
[Object]
0: Object
distance: "0.00006317660849859675"
id: "2"
name: "Pi Kappa Alpha - Epsilon Chapter"
__proto__: Object
length: 1
__proto__: Array[0]
concat: function concat() { [native code] }
constructor: function Array() { [native code] }
every: function every() { [native code] }
filter: function filter() { [native code] }
forEach: function forEach() { [native code] }
indexOf: function indexOf() { [native code] }
join: function join() { [native code] }
lastIndexOf: function lastIndexOf() { [native code] }
length: 0
map: function map() { [native code] }
pop: function pop() { [native code] }
push: function push() { [native code] }
reduce: function reduce() { [native code] }
reduceRight: function reduceRight() { [native code] }
reverse: function reverse() { [native code] }
shift: function shift() { [native code] }
slice: function slice() { [native code] }
some: function some() { [native code] }
sort: function sort() { [native code] }
splice: function splice() { [native code] }
toLocaleString: function toLocaleString() { [native code] }
toString: function toString() { [native code] }
unshift: function unshift() { [native code] }
__proto__: Object
我相信您必须调用
$scope.$apply(),否则AngularJS不会知道任何更改
如果使用内置的$http
,这将自动发生
更多详细信息:您需要在更新公司后应用更改,因为您的帖子超出了角度摘要周期。
你也是
$scope.$apply();
在你的任务完成后,你应该这样做。无论您如何解决$http问题,它都会更干净、更易于使用。这是因为您使用的是jquery而不是$http服务。Angular不会检测来自外部请求(如jquery)的请求的更改。如果出于任何原因想使用jquery而不是$http,则需要调用$scope.apply()来告诉angular某个值已更改
这应该行得通
$.post( "/turnup/index.php/app/companies_near", data,
function(response)
{
$scope.$apply(function(){
$scope.companies = JSON.parse(response);
});
});
$rootScope.Scope#$apply如果您使用的是angular,那么肯定更喜欢$http而不是$。post:
$http({ url:'/turnup/index.php/app/companies_near', method:'POST'})
.success(data) {
$scope.companies = data;
console.log($scope.companies);
});
为什么要使用jquery post请求而不是angular的$http
服务和承诺?我在使用codeigniter(angular的新手)时遇到了问题。不幸的是,我不得不匆忙完成这个项目。你需要在更新你的公司后应用你的更改,因为你的帖子超出了角度摘要的周期。成功了。。我还必须获取scope变量。谢谢
$http({ url:'/turnup/index.php/app/companies_near', method:'POST'})
.success(data) {
$scope.companies = data;
console.log($scope.companies);
});