0
不確定是否所有東西都在這裏正確連線。我們的目標是調用nextSlide函數,讓它更改類,等待一秒鐘,然後將當前圖片加1,然後將類更改回去。我認爲問題在於範圍,但是我沒有在我的代碼中的任何地方使用$ scope,並且它的所有示例都使用它。超時在運行時完全跳過。
如何獲得$超時執行?
var app = angular.module('cole', []);
app.directive('slideShow',['$timeout', function() {
return{
restrict: 'E',
templateUrl: 'slide-show.html',
controller: function(){
this.nextSlide = function() {
document.getElementById("frontPic").className = "fadeOut";
this.$timeout(function() {
this.setCurrent(this.current + 1);
document.getElementById("frontPic").className = "picFront";
}, 1000);
};
},
controllerAs: 'pics'
};
}]);
完整的代碼是在這裏https://github.com/Cameron64/Angular
啊,剛剛扔了一個 var show = this; 隨着你的答案,它的工作!謝謝 – 2014-09-02 02:34:26