this.getData = function () {
$http.get("data/samples.json").then(function(d) {
console.log(angular.fromJson(d.data.cards)[0].title);
return angular.fromJson(d.data.cards);
});
};
this.cards = this.getData();
它将正确的值输出到控制台。
<p>{{main.cards[0].title}}</p>
它什么都不显示,为什么呢?
返回的对象是异步的,并且不返回结果(不能在回调中返回)。试试这个:
this.getData = function () {
$http.get("data/samples.json").then(function(d) {
this.cards = angular.fromJson(d.data.cards);
});
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句