I would like somebody's help on how to change the view within a transition. My problem is that I need to load a view dynamically. So I create a new view (this seems to be working):
var viewname = 'view-'+Date.now();
var element = angular.element(document.querySelector('#view-container'));
var scope = element.scope();
var elementString = '<div id="'+viewname+'" ui-view="'+viewname+'" class="viewunique"></div>';
$compile(element.append(elementString))(scope);
This will add the view to the $view
variable and seems to be working.
My question is: How can I use this new view in a statechange. I tried using the $transition$.$to() like:
$transitions.onStart( {}, function($transition$) {
$transition$.$to().views = {
templateUrl : templateUrl
};
});
where viewname
is the name of the created view, and templateUrl
is the correct template. The template will have it's own controller and stuff. This will overwrite the view for this state, but doesn't really work or do anything.
Somehow I would like to change the views for the state within the transition to this state so that the dynamically created view will be used. Is this possible? Does someone know how this can be done?