誰でも$scope.$on
の作業について説明し、$destroy
はこれらの2つのコントローラでどのように機能しますか。私がルートを変更したときと同じように、別のコントローラが呼び出されると、$destroy
が呼び出されるのはなぜですか? $interval
はどのように初期化されますか?私はpromiseAの下で変数として定義しましたが、まだ初期化されています。私はちょうど要件を満たすために、これらの行をコピーした誰も私がこれらのコード行を理解するのを助けることができますか?短い$scope.$on
を使用して
var myApp=angular.module('myApp',['ngRoute']);
myApp.controller('myController',function($scope){
});
myApp.controller('firstPage',function($scope,$interval){
$scope.thisMessage="First Message";
$scope.firstcall=function(){
var promiseA=$interval(function(){
console.log("First Page");
},10000);
$scope.$on('$destroy',function(){
$interval.cancel(promiseA);
});
}
});
myApp.controller('secondPage',function($scope,$interval){
$scope.thisMessage="Second Message";
$scope.thisMessage="Second Message";
$scope.secondcall=function(){
var promiseB=$interval(function(){
console.log("Second Page");
},10000);
$scope.$on('$destroy',function(){
$interval.cancel(promiseB);
});
}
});
myApp.config(function($routeProvider){
$routeProvider.when("/",{
templateUrl:"First.html"
})
.when("/second",{
templateUrl:"Second.html"
});
});
こんにちは。どうもありがとう – evilBops