簡體   English   中英

Angular無法將json內容返回給對象

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM