0

I'm learning Angular right now and I'm practicing by writing a simple application that uses ngRoute based on this example.

<-- index.html -->
<html>
    <head> ... </head>
    <body>
        <div ng-view></div>
    </body>
</html>

The code from the example displays information about various "Javascript Projects". My question is, how would I create yet another view that displays information about this model?

Say, for example, that I wanted to create one more ngView further down the page that only displays the project names without their descriptions? (See the example)

It seems like I would have to distinguish them from each other somehow. Maybe like this?

<body>
    <div ng-view="fullView"></div>
    ...
    <div ng-view="projectNameView"></div>
</body>

But I don't see anything like that in the documentation, so I think that's probably incorrect. Then I thought maybe I am supposed to use a separate controller like this:

<body>
    <div ng-controller="fullViewController">
        <div ng-view></div>
    </div>
    ...
    <div ng-controller="projectNameViewController">
        <div ng-view></div>
    </div>
</body>

But then the ngViews still seem to be undistinguished from each other.

What is the right way to do this? Once I have an idea from the index.html side, I think I can work out the javascript/module side myself - I just need a little nudge in the right direction.

2 Answers 2

2

You may want to look into ui-router: http://github.com/angular-ui/ui-router.

It provides nested views and easier state management than the default Angular router.

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

Comments

2

Actually only one ng-view is supported per route and for sure that is a down-side of this approach.

As @Jakemmarsh pointed http://github.com/angular-ui/ui-router is option worth considering. Though you have to be aware of:

Warning: UI-Router is pre-beta and under active development. As such, while this library is well-tested, the API is subject to change. Using it in a project that requires guaranteed stability is not recommended.

Some directives that maybe helpful of achieving multiple templates on a single page are:

  1. ng-include -- it includes template/html from a different file.
  2. ng-switch -- switches rendering of html on some conditon.
  3. ng-if -- renders if condition is met.

Comments

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.