[英]Angular can't return json content to object
我正在嘗試將json文件內容添加到對象
var myApp = angular.module('AngularPortfolio', []);
myApp.config( function($interpolateProvider) {
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});
myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http){
$scope.projects = {};
$http.get('../bundles/xxxxxxxxxx/portfolio/data.json')
.success( function(data) {
$scope.projects = data;
})
.error( function(data) {
console.log('ERREUR');
});
}]);
(編輯最新文章)我的JSON文件:
[
{
"title": "example 01",
"img" : "1.jpg",
"filters" : {
"accompagner" : "communication corporate",
"solutions" : "digital"
}
},
{
"title": "example 02",
"img" : "2.jpg",
"filters" : {
"accompagner" : "communication financiere",
"solutions" : "strategies et dispositifs"
}
},
{
"title": "example 03",
"img" : "3.jpg",
"filters" : {
"accompagner" : "communication rse et developpement durable",
"solutions" : "design et identite"
}
}
]
(編輯最新文章)和我的ng-repeat代碼:
<div ng-repeat="item in projects">
<img src="../bundles/xxxxxxxx/uploads/{[{item.img}]}" alt="{[{item.title}]}">
<h3>{[{item.title}]}</h3>
</div>
這段代碼返回的數據像字符串一樣,我無法將其用於ng-repeat。 你能幫助我嗎 ?
非常感謝
取決於您共享的JSON
文件,這將是最終的JSON
輸出,如果不是,請共享您在控制器中獲取的最終JSON
。
<div ng-repeat="item in projects track by $index">
<img ng-src="../bundles/xxxxxxxx/uploads/{{item.img}}" alt="{{item.title}}">
<h3>{{item.title}}</h3>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.