Call AngularJS from Legacy Code
Problem:
You need to integrate AngularJS controls with a legacy Flex application that requires callbacks attached to the DOM window.
Solution:
To dispatch events that AngularJS controllers can listen to from outside the framework, follow these steps:
Get the Scope and Injector:
Obtain the AngularJS Service:
Invoke AngularJS Functions:
Example Usage:
// Get the AngularJS scope and service var scope = angular.element(document.getElementsByTagName('body')[0]).scope(); var service = scope.injector().get('myService'); // Invoke an AngularJS method scope.$apply(function () { service.update(); });
Additional Notes:
The above is the detailed content of How to Integrate AngularJS Controls with Legacy Code Requiring DOM Window Callbacks?. For more information, please follow other related articles on the PHP Chinese website!