javascript - Angular View {{ var }} updating, but $scope.var doesn't change? -


I am using UI-Bootstrap, and I had to face some strange.

The following is used for the markup: Directorate Directory, Rate Value and Rate Max

  & lt; Div class = "RatingContainer text centered" & gt; Two variables are passed in & Lt; Rating value = "rate value" max = "rate max" & gt; & Lt; / Ratings & gt; & Lt; / Div & gt; & Lt; h4 & gt; {{RateValue}} / {{Rate Max}} & lt; / H4 & gt;   

The odd thing is that I can see the rate value variable which is updating in the scene, when I select different stars. But the value of the variable is not updated in the $ diameter view model.

  app.controller ('addModalCtrl', function ($ scope, $ modalInstance, selected movie, myMovieService) {$ scope.rateValue = 0; $ scope.rateMax = 10; $ scope.selectedMovie = Selected movie; $ scope.addToLib = function (items) {var jsonData = {tmdb_id: $ scope.selectedMovie.id, my_rating: $ scope.rateValue // It always remains 0};    

Not sure which is actually going wrong, but I think its scope is primitives due to variables and Not due to objects; which behaves unexpectedly

Normally the variable Instead of using directly it is better to use an object to store the scope values, so you should put your scope variable in an object like this:

  $ scope .vals = { }; $ scope.vals.rateValue = 0; $ scope.vals.rateMax = 10; // etc. Functions do not need to be in an object: $ scope.addToLib = function (items) {// ... < / Code>  

and

  & lt; h4 & gt; {{Vals.rateValue}} / {{vals.rateMax}} & lt; / H4 & gt;    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -