ディレクティブを使ってカウントダウンタイムを作成したいのですが、時間が変化しているときにフェードアウトのようなCSSスタイルを追加する必要があります。私の問題はhtmlバインディングにあります。ここでカウントダウン時間はどのように更新できますか?
私のHTML
<body ng-app="myApp" ng-controller="myCtrl">
<count-down-timer count-down-time=5000></count-down-timer>
{{userCountDownTime}}
</body>
は、ここであなたは何かが変更されたangularJSに通知する必要があり、私のJSコード
app.directive('countDownTimer', function() {
return {
restrict: 'E',
replace: true,
link: function (scope, elem, attr) {
scope.userCountDownTime = attr.countDownTime;
initiate();
function initiate() {
console.log("initiated")
var myVar = setInterval(decreament, 1000);
};
function decreament() {
console.log("decreament");
scope.userCountDownTime--;
console.log(scope.userCountDownTime);
return;
}
}
}});
https://docs.angularjs.org/api/ng/service/$intervalこの方法では、ダイジェストサイクルをトリガーしてコールバック関数でバインドされたパラメータが変更された場合、ビューを更新するように角度を「知っています」 –