0

so I want to load a templateUrl or, invoke $stateProvider on an action other than user input, like onEnter or onload, or just right away at the beginning of the app, but I can't seem to figure it out. Basically I have a simple nav, when clicked they load a partial which shows below the nav etc. I want to show an inital partial as soon as the app is invoked or loaded. below is a sample of my routing:

app.config(function($stateProvider, $urlRouterProvider){

$stateProvider
 .state('page1', {
        url: "/page1",
        templateUrl: "partials/pag1.html"
    })
    .state('page1.stuff', {
        url: "/page1stuff",
        templateUrl: "partials/page1.stuff.html",
        controller: someController
    })
    .state('page2', {
        url: "/page2",
        templateUrl: "partials/page2.html"
    })

any help would be greatly appreciated.

1
  • controller: someController should be controller: 'someController' Commented Jan 28, 2014 at 21:17

1 Answer 1

0

If I understand you correctly you just need a default state

.state('home', {
  url: '',
  templateUrl: 'partials/home.html'
}
Sign up to request clarification or add additional context in comments.

4 Comments

yes but how does home get invoked at runtime? also my example code isn't exactly what I'm working with, basically I'm setting up the state's dynamically using a loop, i thought it would be a bit complicated to explain but here is the state portion of it: $stateProviderRef.state(theState, { url: theUrl, templateUrl: theTemplateUrl, controller: secondaryMenuCtrl })
The home state should be called because the url will be pointing to the root of your website e.g. url: ''. I don't follow you about how you are setting up the state dynamically. Set up a jsbin or something with your code if it doesn't work
alright so I made a plunkr I can't seem to create folders so it doesn't actually work but you can see what I have, I just want to load a partial at start up: plnkr.co/edit/4uFcVHvNXaj1Cgp2hdpe?p=preview
Seems overly complex but I guess yiou need to define your routes that way. I would either define a static home route (e.g. not as part fo the dynamic load) or I would add in the following check if(theState) theUrl = "/" + theState else theUrl = ''

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.