Hi All,
I have a controller that is rendering a view which has deferreds as parameters.
- steal().then(function() {
- 'use strict';
- can.Control('MyControl', {}, {
- init: function() {
- this.render();
- },
- render: function() {
- return can.view('myView.ejs', {
- data: this.options.data // deferred
- }).then(can.proxy(function(fragment) {
- this.element.html(fragment); // this line fails when user navigates to another controller before this deferred is resolved
- }, this));
- }
- });
- });
Normally this works fine, but in certain situations where the user navigates really fast between controllers, the can.view deferred gets resolved AFTER the controller which created it already has been destroyed. Thus, causing the this.element to be null and the render would fail.
The quick solution that I have is to wrap the this.element.html() inside a if(this.element) { // do stuff } block. But is there a better way to handle this type of situation?
Thanks!
Colin