0

I'd like to understand why i can't retrieve data from external sources. I need to recover the content of a Json and parse it to display content in this template :

Nombre of news: {{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>

when i use this code it doesn't work and without any messages:

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: '='
        }
    }
);

but if do not call the data from external like this : it works

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"
                }
            ];
        }
    }
);
1
  • Can you show us the result of console.log($scope.news) after '$http.get' ? Commented Jun 3, 2016 at 8:57

1 Answer 1

1

I'm sorry i found my answer by trying one last thing right after posting this. My mystake was in the loop in the template:

<lignevin class="ligne-vin" ng-repeat="new in news">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.