javascript - Can one AngularJS controller call another?

Published: 12 April 2024
on channel: Code Samples
28
0

Is it possible to have one controller use another?
For example:
This HTML document simply prints a message delivered by the MessageCtrl controller in the messageCtrl.js file.
html xmlns:ng="http://angularjs.org/"
head
meta charset="utf-8" /
titleInter Controller Communication/title
/head
body
div ng:controller="MessageCtrl"
p{{message}}/p
/div

!-- Angular Scripts --
script src="http://code.angularjs.org/angular-0.9..." ng:autobind/script
script src="js/messageCtrl.js" type="text/javascript"/script
/body
/html

The controller file contains the following code:
function MessageCtrl()
{
this.message = function() {
return "The current date is: " + new Date().toString();
};
}

Which simply prints the current date;
If I were to add another controller, DateCtrl which handed the date in a specific format back to MessageCtrl, how would one go about doing this? The DI framework seems to be concerned with XmlHttpRequests and accessing services.


Watch video javascript - Can one AngularJS controller call another? online without registration, duration hours minute second in high quality. This video was added by user Code Samples 12 April 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 28 once and liked it 0 people.