Ben Nadel demonstrates how to use RequireJS inside an AngularJS application by calling the $apply() methods alerting AngularJS to any relevant changes.
As far as AngularJS is concerned, everything "happens" inside of the $apply / $digest lifecycle. This is the period in which AngularJS performs its "dirty checking" of the $scope data, which may or may not precipitate the invocation of various watchers and data-bindings. As such, if your code doesn't trigger an $apply / $digest, AngularJS doesn't know that your code has changed anything.
When you load RequireJS modules, RequireJS loads the target JavaScript files asynchronously before invoking your callbacks asynchronously. This asynchronous nature means that your RequireJS callbacks will be invoked outside of the AngularJS lifecycle. As such, you have to explicitly call $scope.$apply() within your callbacks so that AngularJS will propagate your asynchronous changes throughout the rest of the application.
Your new post is loading...