Give an example for Rootscope in AngularJS?



Give an example for Rootscope in AngularJS?..

Answer / Anjali Verma

$rootScope can be used to broadcast and listen to events across different scopes. Here's an example:

```javascript
// Broadcasting event from a child scope
$scope.$broadcast('eventName', data);

// Listening to the event in a parent scope
$rootScope.$on('eventName', function(event, data) {
console.log(data);
});

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

What is the use of $locale service in angularjs?

1 Answers  


What is the use of @inject()?

1 Answers  


What is innerhtml in angular?

1 Answers  


What is dependency injection (di)?

1 Answers  


What is compile function in angularjs?

1 Answers  


How angular apps prevent this attack?

1 Answers  


What is angular 2?

1 Answers  


Explain ng-hide directive?

1 Answers  


Which framework is best for front end?

1 Answers  


What are the difference between angular 6 and angular 7?

1 Answers  


What is Service in AngularJS?

1 Answers  


What is callback function?

1 Answers  


Categories