0

このディレクティブは、scope.tutorialNumber 変数 (ユーザーがチュートリアルを進めるにつれて増加する) の変化を監視し、tutorialNumber を配列 videoURLs のインデックスとして使用して新しいビデオをロードし、ハードコーディングされた最初のビデオを置き換えます。 htmlに。ただし、tutorialNumber が更新されたときに $watch がまったくトリガーされないようです。なんで?

<video data-setup="{'techOrder': ['html5', 'flash']}"  class="video-js vjs-default-skin" id="myvideo" video-loader="tutorialNumber" id="video" controls>
    <source type="video/mp4" src="file:///C:/Users/Dell/Desktop/grammar%20game/ㅗㅏregular.mp4"></source> 
    Your browser does not support the video tag.
</video>

.directive('videoLoader', function(){
    return function (scope, element, attrs){
            scope.$watch(scope.tutorialNumber, function(){          
                //element.load();           
                scope.video.src(scope.videoURLs[scope.tutorialNumber]);
                scope.video.ready(function(){
                scope.video.play();
                $(scope.video).bind('ended', function(){
                    $(scope.video).unbind('ended');
                    if (!scope.video.ended) {
                        return;
                    }
                    scope.tutorialNumber++;
                    scope.$apply();
                    scope.loadFromMenu();
                });
            });
        });
    }
});
4

2 に答える 2

1

$watch 式を次のように記述する必要があります。

scope.$watch('tutorialNumber', function(){ ...

また

scope.$watch(function(){return scope.tutorialNumber;}, function(){ ...
于 2013-03-01T15:14:00.450 に答える
0

私はこれを間違って読んでいますか、それともスコープ参照が間違って書かれていますか?

ほとんどの場合をscopeリストしましたが、一般的な Angular リファレンスは$scopeです。

また、 というものがあり$rootScopeます。アプリケーション (モデル) の親に値を返すために使用$rootScopeし、ディレクティブまたはモジュール内で $scope を使用してデータを区分化できます。

于 2014-07-11T19:08:05.427 に答える