如何用angularjs读取本地json?
我读取了text.json,并且赋值到$scope.data里了,在html中用ng-repeat没有反应。请问怎么样才能让读取出来的数据分别写到html页面里对应的位置去?
ps:这段代码运行时报错说,找不到json文件的路径404.
js:
function dataController($http,$scope) {
$http.get("json/text.json").success(function(freetrial) { alert(freetrial);$scope.data = freetrial;});
json里的数据:
{"freetrial":[{
"id": "01",
"imgurl": "images/1.jpg",
"status": "0"
},
{
"id": "02",
"imgurl": "images/2.jpg",
"status": "1"
}
]}
html:
<div ng-controller="dataController" ng-repeat="x in data|filter:{status:'0'}">
<div id="{{x.id}}">
<img ng-src="{{x.imgurl}}" />
</div>
</div>
无节操的右脚
9 years, 9 months ago