javascript - Unable to return results from JSON flat file with HTTP get call in AngularJS -
I am trying to remove a hardcod array outside of my code and can convert it to a successful file at any time , So I'm using HTTP to do this.
With the code given below, this is not returning the structure in such a way that I can iterate it in my markup. Also, for some reasons when I look at the firebug and look at the requests, it seems to make the call 4 times (!).
var app = angular Module ('Menu Event App', ['ClaudeRayer']); App.service ('MainEventRepository', ['$ http', function ($ http) {this. $ Http = $ http; this.getMainEvents = function ()} This return. $ Http.get ('/ main_events.json' ). Then (function (feedback) {return response;}}}}}]); App.controller ("MainEventCtrl", ['$ scope', 'MainEventRepository', function ($ scope, MainEventRepository) {$ scope.main_events = MainEventRepository.getMainEvents ();}]); [{"Id": 1, "Roman_Ameloel": "I", "name");
main_events.json
: "Hulk Hogan and Mr. T vs. Rowdy Roddy Piper and Paul Orndorff", "Matinson Square Garden", "State": "New York", "Attendance": 1981} ... and so on ...]
My markup:
ng-repeat = 'main_events' in main_events'
In your controller, complete the promise:
MainEventRepository.getMainEvents (). Then (function (data) {$ Scope.main_events = data;});
Also, return the data object to your service, in response:
Return response. Data;
Comments
Post a Comment