1

i am new to angular i want to create a nested view using angular ui router

i have index.html in this

<div>
  <div ui-view="menu"></div>
  <div ui-view="content"></div>
   <div ui-view="footer"></div>
</div>

in my app.js i use this

 app.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider.state('public', {
        url: "",
        views: {
            'menu': {
                templateUrl: 'app/index/public.menu.html'
            },
            'content': {
                templateUrl: 'app/index/public.content.html'
            },
            'footer': {
                templateUrl: 'app/index/public.footer.html'
            }
        }
    })
   })

in content.html i have

<div>
    <div ui-view="status"></div>
</div>

i want to set default html to that view "status"

and i also want to lode the html according to the url

1 Answer 1

1

There is working plunker

And this is an extract, of the state definition update, supporting both:

  • the ui-view="content" contains ui-view="status"
  • the status url is generated dynamically by the url

State def:

 $stateProvider
    .state('public', {
      url : '/{name:[abc]}',
      views: {
        'menu': { templateUrl: 'public.menu.html', },
        'content': { templateUrl: 'public.content.html', },
        'footer': { template: '<div>footer content</div>', },
        'status@public': {
            templateUrl: function($stateParams){
              if($stateParams.name === "a"){
                return "a.tpl.html";
              } 
              if($stateParams.name === "b"){
                return "b.tpl.html"
              }
              return "c.tpl.html";
            },
        },

The biggest magic is in the status@public name definition, read more here:

The template selection is driven by the feature:

Check the working example

Sign up to request clarification or add additional context in comments.

2 Comments

this is what i exactly i need thanks for the quick reply @Radim Köhler and for the answer
Great if that helped anyhow! Enjoy ui-router ;)

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.