javascript - Angular json data showing in console, but not in the view -


i newbie @ angular , don't know how solve problem. have looked online , read documentation, haven't found proper answer. asked coworkers issue. couldn't figure out assist me, thought best ask guys best way solve is.

basically, app supposed change json data when user clicks link in menu. supposed grab current index , display corresponding data based on index in array. post code have far.

here link code on plunker.

app.factory('quest', ['$http', function($http) {  return $http({ method: 'get', url: 'data/study.json' }).success(function(data) {  return data;  })  .error(function(err) {  return err;  }); }]); 

in order use http requests suggest use following pattern:

app.factory('quest', function($http, $q) {    var promise;    return {       getquests: function() {           // $http returns promise, don't need create 1 $q           promise = $http.get('data/study.json')           .then(function(data) {             return data;           }, function(err) {             return $q.reject(err);           });          return promise;       }    } }); 

so later can fetch factory in controller with:

quest.getquests() .then(function(data) {     $scope.data = data; }, function(res) {     if(res.status === 500) {         // server error, alert user somehow     } else {          // deal these errors differently     } }); 

you can find pattern here: https://stackoverflow.com/a/18383845/1918775

there example of saving data under factory need 1 http request data web-service.


Comments