我有MyExampleController
控制器,它取决于某些可用数据。例如 - 如果myService.dataIsAvailable()
是true
,那么myService
服务中包含该数据。现在我访问某个控制器,我想检查它是否返回true
,如果是,则为init();
,否则如果它变成true
,则触发init();
。我该怎么做?当变量为真或成为真时执行功能
angular.module('angularUiApp').controller('MyExampleController', function() {
function init() {
console.log('do some stuff');
}
// init single time only when myService.dataIsAvailable() is true or execute init() when myService.dataIsAvailable() becomes true.
init();
});