AngularJs: select binding and http request -


I am starting with angular JS and I have a problem with http request and binding selection.

I have a selection menu that is filled in such a way:

  $ http.get ("test"). Success (work (results) (results for (prior. {Services.push (e)})}};   

I use the service variable in HTML like this (I Select2 for the selection menu):

   "service" select ng-model = "RequestCtrl.service" multiple UI-selection2 data-placeholder = "service Without cache ... "class =" default-select "& gt; option ng-repeat =" requestCtrl.services in service "value =" {{service}} "> {{service}} & lt ; / Option & gt; & lt; / select & gt;   

All work is fine for now.

Save the service variable in the variable and I restore it to page loading.

But, in this step, I have a problem. This variable is loaded locally but it does not appear in selection It is empty, if I do not load the selection option from the HTT service, then all the work is fine. So I think there is a problem loading the selection menu.

What's wrong in my code ?

Thanks.

Controller

"Services" as part of the "code" $ . Like this: $ scope.services = [];

Your HTML

  & lt; Option ng-repeat = "Services in Services" ....   

To improve the answer in angular changes, the UI affects when the "vars" area I do not find that relation in your $ http.get and later services.push (e) . This is what I would expect to see:

  $ http.get ("test"). Success (function (result) {result} compensation (work (e) {$ scope.services. Push (e);});});   

On the one hand, I wonder if your result. It can be improved by using the concat function for this:

  $ scope .services = $ scope.services.concat (results);   

Skip your code in this way:

  $ http.get ("test"). Success (work (results) {$ scope.services = $ scope.services.concat (results);});    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -