我有一个这样的控制器(除去一堆东西):)如何从其他地方的脚本调用Angular控制器上的函数?
function SignupController($scope) {
function isDateOfBirthValid(day, month, year) {
// Process day, month and year and return a bool...
// Also update the view model with the appropriate validation message
}
}
函数isDateOfBirthValid(由控制器内部使用,但我也希望能够从外部代码调用它。
(我希望我会被告知这违反了角模式,但它确实可以节省我很多时间......)
怎么办,我需要改变控制器,这样我可以把这个外部功能?我不能仅仅将该功能移到控制器之外,因为该功能以一种重要的方式修改了视图模型的状态。
究竟你 “外” 是什么意思?从另一个Angular-Something或完全独立的外部库? – Scheintod
后者。具体来说,一个jQuery插件的初始化代码。 – David