没有ng-repeat的AngularJS/Json,如何显示数据? [英] AngularJS/Json without ng-repeat, how to show the data?
问题描述
由于某种原因,我必须使用ng-repeat来显示数据.我想不使用ng-repeat来显示数据.
For some reason, I have to use ng-repeat in order to display data. I'd like to display data without using ng-repeat.
角度:
App.controller('aboutLongCtrl', function ($scope, $http) {
$http.get('test_data/ar_org.json')
.then(function (res) {
$scope.aboutlongs = res.data.aboutlong;
});
});
这是我的标记:
<div class="background-white p20 reasons" ng-controller="aboutLongCtrl" >
<h6 ng-repeat="aboutlong in aboutlongs"><b>About {{aboutlong.name}}</b></h6>
<div class="reason-content" ng-repeat="aboutlong in aboutlongs">
{{aboutlong.description}}
</div>
</div>
如果我使用它,它将无法正常工作..有人可以解释为什么吗?
If I use this, it won't work.. can anyone explain why?
<div class="background-white p20 reasons" ng-controller="aboutLongCtrl" >
<h6><b>About {{aboutlong.name}}</b></h6>
<div class="reason-content">
{{aboutlong.description}}
</div>
</div>
我遵循了这种方法,但是它不起作用: 如何在不使用ng的情况下显示单个对象数据-重复?
I followed this approach but it won't work: How to Display single object data with out Using ng-repeat?
我猜这是因为我的角度代码,有些不对.
I'm guessing it's because of my angular code, something isn't right.
推荐答案
可能变量 aboutlongs
是对象数组.
Probably variable aboutlongs
is an array of Objects.
在第一种情况下,ng-repeat指令以给定的次数重复一组HTML.
In first case ng-repeat directive repeats a set of HTML, a given number of times.
如果仍然要访问对象,则可以访问数组索引并显示它.
If you still want to access the Object you can access the array Index and display it.
<div class="background-white p20 reasons" ng-controller="aboutLongCtrl" >
<h6><b>About {{aboutlongs[0].name}}</b></h6>
<div class="reason-content">
{{aboutlongs[0].description}}
</div>
</div>
这篇关于没有ng-repeat的AngularJS/Json,如何显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!