Basically, when you change a model value from an async function which originates outside an angular digest, then you need to call $apply(). This tells angular to do its change detection after the code is complete (you changed the value). Then, angular will notice the changed model value, and using the ng-model directive (it has setup the bindings) it will update the view for you
On 24 November 2014 at 13:47, Tony pee <[email protected]> wrote: > You dont need to update the view manually if you have the $apply: > > element.bind('blur', function (e) { > scope.$apply(function() { > scope.nr = scope.nr * 2; > )); > }); > > Infact its probably better if you dont, as it is being managed by the > ngModel directive > > On 24 November 2014 at 05:18, Adrian Lynch < > [email protected]> wrote: > >> Change this: >> >> element.bind('blur', function (e) { >> scope.nr = scope.nr * 2; >> document.getElementById('watch').innerHTML = scope.nr; >> }); >> >> To this: >> >> element.bind('blur', function (e) { >> scope.$apply(function() { >> scope.nr = scope.nr * 2; >> }); >> document.getElementById('watch').innerHTML = scope.nr; >> }); >> >> Adrian >> >> On 24 November 2014 at 13:03, trzczy <[email protected]> wrote: >> >>> Could you please help me with angular code. The directive has to double >>> increase the value in the textarea but it doesn't. It changes only the text >>> in div that is placed below. But the text in the textarea should be updated >>> too. So both numbers should be the same. To run the directive one has to >>> click inside the textarea and then click somewhere outside the textarea. >>> That is the code: jsfiddle <http://jsfiddle.net/9mFpp/814/> that does >>> not work. >>> Thanks in advance >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "AngularJS" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/angular. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "AngularJS" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Tony Polinelli > > -- Tony Polinelli -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
