factory - How to assign a back end data value to a string variable in AngularJS? -


I was trying to define a global variable that values ​​2/3 different templates (instructions) Will show in For this, I have used the Coiner factory as follows:

  app.factory ('MyService', function ($ http) {return {firstNumber: function () {// return selectedNumber = "200 "; Var selectedNumber =" "; var selectNumber = $ http.get (" / count.do "). Success (function (data) {console.log ('first number:', data [0]. Count)}) ; Return selected number;}};});  

As you can see 'Selected numbers' it is a normal variable. The problem occurs when I codify the value as "200" and the controller calls the following as follows:

  // init number $ scope.selectedNumber = MyService.firstNumber ();  

This entire process is working fine. But as soon as I'm trying to get back the value (which you can see above) {} you can get the object.

I did some research on this and understand that my concept on angular object and string manipulation is not clear ... can someone help me to understand my mistake and to solve this situation for.

OK, I have received the required result as follows, using the 'callback' service:

In my factory I just said '$ http.get':

  App.factory ('MyService', function ($ http) {return {first number: function () {$ Http.get ("/ count.do"). Success (callback);}};});  

And then I received the data from the controller and is assigned as follows:

  // Init number MyService.firstNumber (function (data) { $ Scope SelectedNumber = data [0]. Count;});  

I do not know whether this is a good solution or what will be really appreciated for any comments on this solution, plz

Thanks


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -