MyExampleController
コントローラは、利用可能な特定のデータに依存します。例えば、myService
サービスの場合、myService.dataIsAvailable()
がtrue
の場合、そのデータが入っているサービス。今度は特定のコントローラにアクセスし、true
を返すかどうかを確認したい場合はinit();
、それ以外の場合はtrue
になると、init();
が発生します。どうすればいいのですか?変数がtrueまたは真となったときに関数を実行
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();
});