0

I have been through several similar questions here on this and still cannot figure out what I am doing wrong. I am looking to load a view within a view (which also happens to be within another view).

The code in rules.html is not appearing. Am I misunderstanding the concepts behind ui-router?

In the firefox developer console I am simply getting <!-- uiView: rules -->

index.html

<body ng-app="App">
   <div class="container" ui-view="container" ></div>
</body>

parent.html

<div>
    //some wrapper stuff
    <div ui-view="parent"></div>
</div>

edit-entity.html

<div ng-controller="ProjectManagerController as data">
        // other code showing fine
        <div ui-view="rules"></div>
        // other code showing fine
</div>

rules.html

<div>TEST CODE</html> 

app.js

$stateProvider
    .state('app', {
        views: {
            'container': {
                templateUrl: 'views/parent.html?nd=' + Date.now(),
                controller: 'MainController as data'
            }
        }
    })
    .state('edit-entity', {
        parent: 'app',
        url: '/entity/{id:int}/edit',
        views: {
            'parent': {
                templateUrl: 'views/entity-edit.html?nd=' + Date.now(),
                controller: 'MainController as main'
            }
        }
    })
    .state('rules', {
        parent: 'edit-entity',
        views: {
            'rules': {
                templateUrl: 'views/rules.html?nd=' + Date.now(),
                controller: 'MainController as data'
            }
        }
    });

EDIT: I have also tried rules.entity

1
  • Did my solution solve your problem? Commented Aug 14, 2017 at 2:53

2 Answers 2

1

You need to trace the path in a nested state from the parent state. Edit: I have added a Plunker for your work: http://plnkr.co/edit/mBYdUTEkaLsqhI6MNW4I?p=preview

.state('app', {
  views: {
      'container': {
          templateUrl: 'views/parent.html?nd=' + Date.now(),
          controller: 'MainController as data'
      },
      'container.parent@app': {
          templateUrl: 'views/entity-edit.html?nd=' + Date.now(),
          controller: 'MainController as main'
      }
      'container.parent.rules@app': {
          templateUrl: 'views/rules.html?nd=' + Date.now(),
          controller: 'MainController as data'
      }
   }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but are you sure this is fully correct? Im a bit lost as to why edit-entity is a parent of app and also not sure where this order is coming from container.parent.rules.edit-entity, should it not be container.parent.edit-entity.rules?
@Adrian so sorry the parent was a typo. I have updated it
0

Can you try if this works -

.state('rules', {
    parent: 'edit-entity',
    views: {
        'rules@edit-entity': {
            templateUrl: 'views/rules.html?nd=' + Date.now(),
            controller: 'MainController as data'
        }
    }
});

I just added the '@' after the view name (absolute naming). You can read more here - https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views#view-names---relative-vs-absolute-names. I've found that this works for me sometimes.

1 Comment

thanks for the help but unfortunately no joy. I had tried something like that earlier alright. Very strange!

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.