繁体   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