I have the function notifications.get()
that runs every 10 seconds.
function notificationsCtrl($scope, $interval) { $interval(function(){ $scope.notification = notifications.get(); $('.card').addClass('rotate'); }, 10000); };
But when the page is loaded, the function should be called once immediately. Can anyone help me?
AngularJS's wrapper for window. setInterval . The fn function is executed every delay milliseconds. The return value of registering an interval function is a promise. This promise will be notified upon each tick of the interval, and will be resolved after count iterations, or run indefinitely if count is not defined.
You need to call unsubscribe() on the subscribe variable.
In AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application. AngularJS has about 30 built-in services. One of them is the $location service.
You can do it like this,
$interval()
for execute in every 10 sec.CODE:
function notificationsCtrl($scope, $interval) { var fun = function(){ $scope.notification = notifications.get(); $('.card').addClass('rotate'); }; fun(); $interval(fun, 10000); };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With