Home >Web Front-end >JS Tutorial >Can AngularJS Services and Controllers Interact with External Code?
Calling AngularJS from Legacy Code
You aim to integrate AngularJS with a legacy Flex application by attaching callbacks from the Flex app to the DOM window. To achieve this, you can create services that AngularJS controllers can listen to. But can you update a service from outside of AngularJS, and can a controller receive events from a service?
Solution:
Accessing AngularJS from external code is comparable to debugging it or integrating it with third-party libraries. Here's how to interact with DOM elements:
Using the injector, you can access any service in the Angular application. Likewise, from the scope, you can invoke any published methods.
Remember to wrap any model adjustments or scope method calls in $apply():
$scope.$apply(function(){ // Perform model changes or method invocations on the Angular app here. });
The above is the detailed content of Can AngularJS Services and Controllers Interact with External Code?. For more information, please follow other related articles on the PHP Chinese website!