2013-03-18 29 views
1

我是Angularjs的新手,我試圖用soundManager庫創建一個簡單的播放器。angularjs與soundmanager,在加載時更新DOM

我正面臨的問題是關於在聲音加載/播放期間更新DOM。

soundManager Sound對象公開了一些動態屬性,如bytesLoadedposition,我試圖弄清楚如何將它們綁定到DOM。

我的東西試過像

<span ng-bind="sound.bytesLoaded"></span> 

其中sound是附着在根$scope聲音對象的實例,但似乎DOM以這種方式只更新一次。

回答

2

問題可能是sound.bytesLoaded在非角度世界中更新,比如加載的字節的回調函數或一些類似的非角度世界的回調方法。

要在更新非角度世界中的模型值時更新視圖,您可能需要在SM2的回調方法內調用$scope.$apply方法。

一些僞代碼:

sound.on('bytesLoaded', function(bytesLoaded){ 
    // Imagine you have some similar kind of the callback in SM2, 
    // where you will be updating the sound.bytestLoaded property. 
    sound.bytesLoaded = bytesLoaded; 
    $scope.$apply(); // please make sure you call have this line 
        // where you are updating the bytesLoaded property. 

}) 
+0

感謝回答。這似乎對我有意義,即使我對'$ apply'方法不太自信。我覺得Angularjs doc有點難以探索。 – 2013-03-18 10:10:41

+0

它可能對其他人有幫助:http://docs.angularjs.org/misc/faq(Section:$ watch&$ apply) – 2013-03-18 12:03:18