Issue
I have a video on the homepage of my app which plays when I launch it. When the video ends I'd then like to use some CSS 3 transitions to move the page around.
<ion-view hide-back-button="true" title="">
<ion-pane>
<div class="home-video">
<video autoplay="autoplay" ng-click="ctrl.video()" aria-label="video of IBM logo" tabindex="-1" aria-hidden="true" poster="images/Hero_Final_Placeholder.gif" onended="ctrl.video()">
<source src="videos/video.mp4" type="video/mp4">
<img src="images/video_backup.gif" title="Your browser does not support the video tag.">
</video>
</div>
</ion-pane>
</ion-view>
At the end of the video I'd like to be able to call an angularJS Controller function.
'use strict';
angular.module('app', ['ionic']).config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('home', {
url: "/home",
templateUrl: 'views/home.html',
controller: 'homeCtrl as ctrl'
}).state('project', {
url: "/project/:projectId",
templateUrl: 'views/project.html',
controller: 'projectCtrl'
});
// Default view to show
$urlRouterProvider.when('', '/home');
}).run(function ($http, pouchDB, replicationService, $rootScope) {
replicationService.replicate();
});
My controller looks like:
'use strict';
var app = angular.module('app', false);
app.controller('homeCtrl', function ($rootScope){
this.data = {};
var ctrl = this;
this.video = function () {
console.log("video done");
}
});
If I put a console.log()
in the <video onended="">
element it prints it out. If I try and call ctrl.video()
which contains the same console.log I get the following error:
Uncaught ReferenceError: ctrl is not defined
I know that ctrl is defined because if I add an ng-click="ctrl.video()"
and I click the video player it prints out.
Solution
Eventually what I did was use Angular UI Utils which has a generic event binder. This allowed me to bind to an event that AngularJS doesn't out of the box. Using the following line ui-event="{ ended : 'ctrl.video()'}"
I was able to call my function when the video ended which gave me the desired behaviour.
Answered By - Sam Marland
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.