vendredi 12 février 2016

How can I trigger an action to draw on a canvas immediately after the template loaded?

I want to draw on a canvas in a template immediately after the template loaded, so I think I need a suitable hook (event) to do it but I could not find one.

I read the answer for How can I trigger an action, when a template is loaded in ember? and I tried to use "setupController" event to do it but it did not work.

template.hbs

<canvas id="lyric-editor" width="200" height="200"/>

route.js

import Ember from 'ember';
export default Ember.Route.extend({
  setupController: function() {
    var canvas = document.getElementById('lyric-editor');
    console.log(canvas:" + canvas); 
    // the result is null, it means the template is not loaded at this time.
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = 'white'; // Color of the bars
    ctx.fillRect(50, 50, 40, 40);
  }

There are beforeModel method and afterModel method in the Ember.route class so I expected something like afterTempalteLoad method.

Any hints are appreciated, Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire