Reputation: 16282
I am new to AngularJS. Please see the code below and tell me what it is doing.
$scope.$on('$viewContentLoaded', function(event) {});
How to use it in a controller to access the DOM?
$timeout(function() { });
I am looking for explanation and example of how to use $scope.$on()
and $timeout()
in real life and what it does.
Upvotes: 0
Views: 470
Reputation: 2583
$scope.$on
registers a listener for the event passed as the first parameter and executes the function passed as the second on each instance of said event. $broadcast
and $emit
can be used to send out custom events of your own.
$timeout
can be used in place of setTimeout
but when called with no delay argument will simply wait for the next digest before executing its callback function.
As for DOM manipulation, this should not be carried out in a standard 'jQuery like fashion'. If manipulation of the DOM is required a custom directive can be defined to encapsulate this functionality and therefore allow the Angular framework to govern its syncopation.
Upvotes: 4