angularjs - Angular: Setting variables inside $on events, need to call $apply? -


i using angular module sends messages , trying set variable true or false notice not updated in ui unless wrap them inside $apply. best way of doing this.

this working code, remove $apply , although variable updated - view never updates.

  $scope.$on('duscrollspy:becameactive', ($event, $element, $target) => {         $scope.$apply(() => {           this.ready = true;         });     }); 

anyone ideas best way fix ? calling $apply seems code smell, know listening events on scope isn't considered practice 3rd part angular module.

thanks

modifying scope inside event requires call $apply(). (this bound scope btw)

there's no way around it. (if need view updated.)

$apply called automatically in many places $http promise resolve code (https://github.com/angular/angular.js/blob/master/src/ng/http.js line 1331-1351) it's not called on events.

note, line numbers may change. search function done()

so not code smell, standard.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -