Skip to content

Angular UI Router replace view on runtime #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jribeiro opened this issue Jul 2, 2014 · 2 comments
Closed

Angular UI Router replace view on runtime #1179

jribeiro opened this issue Jul 2, 2014 · 2 comments

Comments

@jribeiro
Copy link

jribeiro commented Jul 2, 2014

I'm trying to change a parent view template on runtime - inside a service. I've looked at an issue which seems related: #379

My app config looks like:

$stateProvider
.state('base', {
    abstract: true,
    views: {
        'header':       {
            controller: 'HeaderCtrl',
            templateUrl: 'header.html'
        },
        '': {
            template: '<div ui-view="main"></div>'
        }
    }
})
.state('base.home', {
    url: '/',
    views: {
        'main': {
            controller: 'SomeContentCtrl',
            templateUrl: 'content.html'
        }
    }
});

I then have a service which is called from SomeContentCtrl that will listen for an event and upon such event I want to set the templateUrl for the header to null. Something like:

angular
    .module('RemoveTemplate', [ ])
    .factory('RemoveTemplate', ['$window', '$view', '$state',
        function RemoveTemplate ( $window, $view, $state ) {

            var windowElem  = angular.element($window);

            var listen   = function ( ) {
                windowElem.on('RemoveTemplate', function ( event ) {
                    $view.load('header@base', {
                        templateUrl: null
                    });

                    // Trying both, even tried without refreshing the state
                    $state.reload();
                    $state.go('wh.lobby');
                });
            };

            return {
                listen:  listen
            };

        }
    ]);
});

But this doesn't seem to work. Is there a way of achieving this with Angular UI Router? If not is this something on the roadmap?

@franck86
Copy link

franck86 commented Dec 3, 2014

Hello guys . I need exactly the same thing . Any news on the use of the $ view provider? thanks

@nateabele
Copy link
Contributor

Is there a way of achieving this with Angular UI Router?

Not currently.

If not is this something on the roadmap?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants