filmov
tv
javascript - Can one AngularJS controller call another?

Показать описание
Is it possible to have one controller use another?
For example:
head
meta charset="utf-8" /
titleInter Controller Communication/title
/head
body
div ng:controller="MessageCtrl"
p{{message}}/p
/div
!-- Angular Scripts --
/body
/html
The controller file contains the following code:
function MessageCtrl()
{
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.
For example:
head
meta charset="utf-8" /
titleInter Controller Communication/title
/head
body
div ng:controller="MessageCtrl"
p{{message}}/p
/div
!-- Angular Scripts --
/body
/html
The controller file contains the following code:
function MessageCtrl()
{
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.