0

我想了解为什么我无法从外部来源检索数据。我需要恢复 Json 的内容并对其进行解析以在此模板中显示内容:

新闻名称:{{new.length}}

<div>
    <lignevin class="ligne-vin" ng-repeat="new in $ctrl.news">
        <etiquevin class="etiquettevin">
            <img class="etiquette" src="{{new.img}}"/>
        </etiquevin>
        <descriptifvin class="descriptif-vin">
            <p class="title">{{new.name}}</p>
            <p class="sub-title">{{new.ref}}</p>
            <p>{{new.prixTotal}}</p>
            <p>{{new.prixUnit}}</p>
        </descriptifvin>
    </lignevin>
</div>

当我使用此代码时,它不起作用并且没有任何消息:

function NewsListCtrl($scope, $http) {
    $http.get('http://myndd/myfile.json').success(function (data) {
        $scope.news = data;
        console.log($scope);
    });
};

angular.
    module('myApp').
    component('newsList',{
        templateUrl :'templates/newsdetail.html',
        controller: NewsListCtrl,
        bindings: {
            news: '='
        }
    }
);

但是如果不要像这样从外部调用数据:它可以工作

angular.
    module('myApp').
    component('newsList',{
        templateUrl :'templates/newsdetail.html',
        controller: function NewsListCtrl(){
            this.news=[
                {
                    "id": 1,
                    "name": "name1",
                    "ref": "ref1",
                    "conditionnement" : "cond1",
                    "prixTotal": "10,00€",
                    "prixUnit" : "1,00€",
                    "img": "http://myndd/myfile1.png"
                },
                {
                    "id": 2,
                    "name": "name2",
                    "ref": ref2",
                    "conditionnement" : "cond2",
                    "prixTotal": "20,00",
                    "prixUnit" : "2,00€",
                    "img":"http://myndd/myfile2.png"
                }
            ];
        }
    }
);
4

1 回答 1

1

很抱歉,我在发布此内容后立即尝试了最后一件事,从而找到了答案。我的赌注在模板的循环中:

<lignevin class="ligne-vin" ng-repeat="new in news">
于 2016-06-03T09:06:42.987 回答