如何在不使用ng-repeat的情况下显示单个对象数据? [英] How to Display single object data with out Using ng-repeat?
本文介绍了如何在不使用ng-repeat的情况下显示单个对象数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目标:-仅显示单个对象数据. 我必须使用ng-repeat来获取对象吗?
Aim :- To display only Single Object data. Do I have to use ng-repeat to get the object ?
我对棱角还比较陌生.有更好的方法吗?
I'm relatively new to angular. Is there a better way to do this?
HTML视图:-
<div ng-controller="dashboardController">
<div ng-repeat="person in persons">
<span class="name">{{person.name}}</span>
<span class="title">{{person.title}}</span>
</div>
</div>
控制器代码:-
.controller('dashboardController', ['$scope', function(scope){
scope.persons = [
{
name:"George Harrison",
title:"Goof Off extraordinaire"
}
];
}])
为我的同伴更新,数组与单个数据集:
UPDATE FOR MY FELLOW NOOBS, array vs single data set:
scope.persons = [ <-- that creates an array. Cant believe I forgot that.
scope.persons = { <-- that creates a single data set
推荐答案
scope.persons是一个数组,因此您必须使用ng-repeat. 如果您的数据是对象,则无需使用ng-repeat. 前任: 您的控制器
scope.persons is an array so you have to use ng-repeat. if you your data is an object, you don't need to use ng-repeat. ex: your controller
.controller('dashboardController', ['$scope', function(scope){
scope.person ={
name:"George Harrison",
title:"Goof Off extraordinaire"
}
}]);
所以你的html:
<div ng-controller="dashboardController">
<div>
<span class="name">{{person.name}}</span>
<span class="title">{{person.title}}</span>
</div>
这篇关于如何在不使用ng-repeat的情况下显示单个对象数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文