我有一个初学者问题,我的AngularJS非常简单的代码:我试图从工厂传递数据到控制器并打印返回到我的视图的对象,这里是我的代码:AngularJS:不能从工厂访问对象属性
angular.module('app').factory('blogFactory',function(){
return {
//EDIT
post:{"author":"Bob","name":"smith","content":"some content"},
read: function(){
return this.post;
}
}
});
在控制器:
angular.module('app').controller('MainCtrl',['$scope','blogFactory'], function($scope, blogFactory){
$scope.datas = blogFactory.read();
console.log($scope.datas);});
当我console.log($scope.datas
它记录所述对象细。在视图中,我无法访问该对象的属性:
<section class="overview">
<article ng-repeat="data in datas">
<p>{{data.name}}</p> //Doesn't display anything
<p>{{data}}</p> // Displays the object
</article>
</section>
有没有人有任何想法?在此先感谢
为$ scope.datas数组? – mohamedrias 2015-04-04 05:13:43