Friday, May 17, 2024
115
rated 0 times [  121] [ 6]  / answers: 1 / hits: 91860  / 12 Years ago, mon, may 7, 2012, 12:00:00

I'm using AngularJS to build HTML controls that interact with a legacy Flex application. All callbacks from the Flex app must be attached to the DOM window.



For example (in AS3)



ExternalInterface.call(save, data);


Will call



window.save = function(data){
// want to update a service
// or dispatch an event here...
}


From within the JS resize function I'd like to dispatch an event that a controller can hear. It seems that creating a service is the way to go. Can you update a service from outside of AngularJS? Can a controller listen for events from a service? In one experiment (click for fiddle) I did it seems like I can access a service but updating the service's data doesn't get reflected in the view (in the example an <option> should be added to the <select>).



Thanks!


More From » actionscript-3

 Answers
53

Interop from outside of angular to angular is same as debugging angular application or integrating with third party library.



For any DOM element you can do this:




  • angular.element(domElement).scope() to get the current scope for the element

  • angular.element(domElement).injector() to get the current app injector

  • angular.element(domElement).controller() to get a hold of the ng-controller instance.



From the injector you can get a hold of any service in angular application. Similarly from the scope you can invoke any methods which have been published to it.



Keep in mind that any changes to the angular model or any method invocations on the scope need to be wrapped in $apply() like this:



$scope.$apply(function(){
// perform any model changes or method invocations here on angular app.
});

[#85722] Sunday, May 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
everett

Total Points: 317
Total Questions: 112
Total Answers: 109

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;