function () {//monitor video playback time if (media.currenttime>1) {//If the video is longer than 1 seconds $scope. scoreshow=true;//score box pops up
Console.log ($scope. scoreshow);//true };
},true);
Add a listener event to a video media object: When Timeupdate, the callback function executes normally, $scope. Scoreshow also becomes true, but on the HTML page
<!--scoring bullet frames--
<Divclass= "Videomessage"Ng-show= "Scoreshow"> <P>Make a point and leave your attitude!</P> <Pclass= "Btns"> <spanNg-click= "Confirmscore ()">Are you sure</span> <spanNg-click= "Ignorescore ()">Ignore</span> </P></Div>
Video playback to 1 seconds later, the scoring bullet box is always not displayed, and in the page's console to see the Scoring bullet box, display:none! Important
Note that $scope.scoreshow does not actually work.
The strange point is:
If there is a line in the same controller: $interval (function () {},0);
As follows
Media.addeventlistener (' timeupdate ', function() {//Listen for video playback time if (media.currenttime>1) {//If the video is broadcast for longer than 1 seconds $scope. Scoreshow=true;//Scoring Box Popup
Console.log ($scope. scoreshow);//true };
},true);
$interval (function() {},0);
The scoring bullet box will be displayed.
However, if you replace the $interval with the native code setinterval, the scoring bullet box will not be displayed.
Focus:
Therefore, infer: because Ionic does not know the native code does some things, so do not know $scope.scoreshow change, to ionic know need to use $scope. $apply () Wrap the $scope.scoreshow=true up:
function () {// monitor video playback time if (media.currenttime>1) {// If the video broadcast time exceeds 1 seconds $ Scope. $apply (function() { $scope. scoreshow =true; the score box pops up }) ; },true);
So $scope.scoreshow not just become true, but also really play a role, the scoring frame shows.
Note:
Quote a passage from http://www.2cto.com/kf/201311/256848.html to explain: when to use $apply ()
So when exactly do we need to call the $apply () method? The situation is very small, virtually all of our code is wrapped in $scope. $apply () inside, like Ng-click,controller initialization, $http destroy function, etc. In these cases, we do not need to call ourselves, in fact, we can not call ourselves, otherwise the $apply () method inside the call $apply () method will throw an error. If we need to run the code in a new execution sequence, we really need to use it, and if and only if the new execution sequence is not created by the method of the angular JS library, we need to use the code in $scope. $apply () Wrap It Up
Ionic in $interval and $apply ()