jeudi 23 avril 2015

Angularjs - $http request does not work from inside a function

In the controller i would like to put the http request of a json file into a function. Only when its outside of a function it works. Why? I would like to display the contents in the view.


$http.get('components/json/list.json').success(function (data) {
    main.listNoFunction = data;

main.listFunction = function () {
    var result = null;
    $http.get('components/json/list.json').success(function (data) {
        result = data;
    return result;


// This works:
{{ main.listNoFunction }}

// This works NOT:
{{ main.listFunction }}

Thanks for your help! Vin

Aucun commentaire:

Enregistrer un commentaire