0

I'm using a HTML5 range slider to set a value (status) and send it to a db. The problem I'm having now is that when I reload the page the slider and it's value are always set on '50'. The slider is generated inside an ng-repeat from angularjs. When I change the value in the db I see that the 'value' from the slider is changing, but nothing happens with the gui...

Can someone help me with this issue? Thanks in advance...

<h3 style="text-align: center">{{dim1}}</h3>
<input ng-model="dim1" ng-touchend="dim_switch(node, dim1)" ng-mouseup="dim_switch(node, dim1)" id="dimslider" value="{{parseInt(node.status)}}" type="range" step="1" min="0" max="100">
9
  • Use localStorage to set the value and get back same value on reload the application Commented May 29, 2017 at 8:19
  • parseInt() won't evaluate in angular expression, move it to some controller method and call method from UI. Commented May 29, 2017 at 8:20
  • @anoop - Call it from ngChange ? Tried that approach but it gave me errors and called the function several times, even when there were no changes... Commented May 29, 2017 at 8:24
  • @RohitJindal It should work realtime and not only on reload (i check db data every ... second and push changed values to the ngrepeat) Commented May 29, 2017 at 8:25
  • When I remove the ng-model from the input tag it works on page reload... But still not realtime -> i have made also buttons from simple input buttons and those work realtime Commented May 29, 2017 at 8:31

2 Answers 2

1

Since ng-repeat creates a new child scope.(doc.).

hence your $soppe.dim1 gets overidden by the new child scope. So wrap your property by hierarchical model to leverage javascript prototypical inheritance., and persist your $scope property.

like $scope.slider = {dim1 : ''} and use it in HTML like : {{slider.dim1}}.

further : parseInt() won't evaluate in angular expression, move it to some controller method.

Like: ng-value="someMethod(node.status)" and from controller method return parseInt(statusParam)

Sign up to request clarification or add additional context in comments.

4 Comments

I think I understand what you mean, but i have a lot of elements in my ng-repeat... + The parseInt i removed by using an int value in my database and not a string anymore...
@AlexLogist: then add some sliderValue variable in your ng-repeat dataArray, like ng-repeat = "data in dataArray" and in html {{data.sliderValue}}.
Still not updating the Gui
@AlexLogist: please create some plunker\fiddle to reproduce issue, or update mine link
0

Seems that the HTML5 range slider does not use the "value" attribute -> problem solved with a combination of the given solution !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.