Skip to content

State with no template #55

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
soundstep opened this issue Sep 2, 2013 · 2 comments
Closed

State with no template #55

soundstep opened this issue Sep 2, 2013 · 2 comments
Milestone

Comments

@soundstep
Copy link

It would be nice to have a way of setting states that doesn't load templates but just instantiate a controller.

In the following example, navigate to /main would show the template, resolve the data and create the controller.

Navigate to /main/sub would only create the controller, this would be a great freedom.

.state('main', {
    route: '/main',
    views: {
        'main': {
            template: 'main.html',
            controller: 'MainController'
        }
    },
    resolve: {... load data here...}
})

.state('main.sub', {
    route: '/:sub',
    views: {
        'whatever': {
            controller: function() {

            }
        }
    },
    resolve: {... load data here...}
});

I had to do this task as the sub route was supposed to open a bootstrap modal window. In this case I don't want to create any html, I just want to handle a route and execute custom code to show the modal window.

I solve the problem loading an empty template in an empty hidden view, not ideal.

Is that already possible? if not, it would be a useful addition.

@jeme
Copy link
Contributor

jeme commented Sep 2, 2013

Try to look at transitions if that fits your purpose.

@jeme
Copy link
Contributor

jeme commented Sep 3, 2013

To elaborate a bit, start here: angular-ui/ui-router#133

UI Route has actually had the same discussions about controller with no views, but this isn't feasible as the implementation is, also I don't think it makes sense because controllers are a thing from MVC, so they are tightly bound with a View and a Model.

However what we have instead is "actions on state" which is what transitions really mostly are... It would be neat with a more simple syntax maybe, but the behind the scenes wouldn't be much different.

With Angular Routing you have to additional option to hook in at different stages of the actual transition.

There is some lack of resolved values and also the ability to maybe inject them into "transitions" somehow... I will have a look at that...

As for your scenario on only running the controller again, this is where Refresh comes into the picture, again there is a missing link to resolve though, but you can go in and call refresh on a controller, if you wrap all you controller logic inside this, it would simulate that behavior quite well.

.state('main', {
    route: '/main',
    views: {
        'main': {
            sticky: "42",
            template: 'main.html',
            controller: 'MainController'
        }
    },
    resolve: {... load data here...}
})

.state('main.sub', {
    route: '/:sub',
    views: {
        'whatever': {
            sticky: "42",
            template: 'main.html',
            controller: 'MainController'

            }
        }
    },
    resolve: {... load data here...}
});

@jeme jeme closed this as completed Oct 9, 2013
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

2 participants