假设这只手表位于指令内,可以像这样从主控制器观察变量吗?这是整个指令。当它看起来像这样,手表确实会在首页加载时触发,但不会再次触发。我不会将questionNumber传递给指令。这是为什么它不知道它?我可以在指令中看到控制器范围属性吗?
.directive('videoLoader', function() {
return function (scope, element, attrs) {
scope.$watch(attrs.videoLoader, function() {
element[0].load();
element[0].play();
$(scope.video).bind('ended', function() {
$(this).unbind('ended');
if (!this.ended) {
return;
}
scope.tutorialNumber++;
scope.$apply();
scope.loadFromMenu();
});
});
scope.$watch(scope.questionNumber, function(){
if (scope.sectionNumber === 0 && scope.tutorialNumber === 0) { //if first video play congratulations etc
if (scope.questionNumber === 1) {
start(164.15);
pause(166.8);
} else if (scope.questionNumber === 2) {
start(167.1);
pause(170);
} else if (scope.questionNumber === 3) {
start(171.1);
}
}
});
}
})
我会记住这一点,并不是说我根本不会陷入沉重的压力,它只是因为如果你开始逐渐消失,这个特定的应用程序并不真正起作用,没有任何事情可以独立工作。无论如何,谢谢你的伟大答案 – Tules 2013-03-03 18:58:32