javascript - Updating scope from outside AngularJs without using "angular.element.scope" -


i'd able update scope in angular function outside angular.

e.g., if have jquery plugin returns success callback, i'd able update scope success callback. every solution i've seen involves calling angular.element(selector).scope , calling $apply on scope returned. however, i've seen many comments indicating doesn't work when debug info off , isn't recommended, haven't seen alternative solutions.

does know of way update scope outside of angular without using angular.element(selector).scope?

here accepted solution in post:

"you need use $scope.$apply() if want make changes scope value outside control of angularjs jquery/javascript event handler.

function change() {     alert("a");     var scope = angular.element($("#outer")).scope();     scope.$apply(function(){         scope.msg = 'superhero';     }); } 

here warning .scope() doesn't work when debug data off in post:

"fyi according docs using .scope() requires debug data enabled using debug data in production not recommended speed reasons. solutions below seem revolve around scope() – rtpharry dec 5 '14 @ 15:12 "

i don't see alternative solution using .scope() in post or in other similar posts.

angularjs access scope outside js function

thanks!

update 1 possible solution not using angular.element(selector).scope assigned scope in controller using firstctrl window object. injected $window firstctrl controller , did following:

$window.firstctrlscope = $scope; 

then jquery or other javascript do:

var scope=window.firstctrlscope; scope.$apply(function () {       // update scope }); 

is solution or there better solutions updating scope without using angular.element(selector).scope?

thanks!

i think both ways bad. design sets controllers global variables, or access scope html element leads unmaintainable application many hidden links.

if need cooperate jquery plugins (or other non-angular code), wrap directive clear api (attributes, bindings , callbacks).


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -