Thursday, 15 July 2010

javascript - Setting controller attributes inside ajax call -


I'm new to AngularJS and I'm skeptical about controlling properties. I have created a feature called anonio, this feature has an array of objects, as shown in the image:

  var anuncioModule = angular.module ('anuncioModule', []) ; AnuncioModule.controller ('RegistrationController', ['$ http', function ($ http) {this.anuncios; this.loadAnuncios = function loadAnuncios () {$ http.get ('http: // localhost: 8080 / pederofer / anuncios /get.action '). Then (function (result) {this.anuncios.push.apply (this.anuncios, result.data);})}}}]);  

When I call my web service with function loadAnuncios and try to set the value directly by using "this.anuncios", then give me the "this.anuncios undefined" message get. But if I create a version called anNnx and set "this.anuncios = anucs", and instead set my AJAX to call directly. Anonymous I set the acute as the image , Does it work.

  Vir INVO module = Angular Module ('Anuscomomo Module', []); Var anuncs = []; AnuncioModule.controller ('RegistrationController', ['$ http', function ($ http) {this.anuncios = anuncs; this.loadAnuncios = function loadAnuncios () {$ http.get ('http: // localhost: 8080 / pedirofor /ununcios/get.action '). Then (work (result) {anuncs.push.apply (anuncs, result.data);})}}  

My question is, why it Works?

I can suggest suggestions about what you are doing in a different way

  var anuncioModule = angular.module ('anuncioModule' []); AnuncioModule.controller $ Scope.anuncios = []; $ Scope.loadAnuncios = function () {$ http.get ('http: // localhost: 8080 / pedirope / annaccio / gate action'). Then (function (result) {$ scope .anuncios = result. Data;});}}}  

I do not know what it really is after you, but it may be that


No comments:

Post a Comment