angular/angular.js — pull request #1198 by hkdobrev (2012-07-24 14:08:44+00:00)
Title: Multiple named ngView directives and attaching views to routes

Usage and purpose
=================

Routes can have a view attached via the `view` property.
Views can be named like so:
``` html

```

Then you could create a route which will update only this view:
``` js
$routeProvider.when('/somepath', {
templateUrl: '/section-template.html',
view: 'subsection'
});
```

When the url is changed to '/somepath' only views named 'subsection' would
be updated. This should be used for:

- subsections on the page which should respond to some routes,
other views would not be changed

- modal dialogs with their own url, like Pinterest, Trello etc.

Different Cases
===============

- a view has a name, but the route does not have a view set

* the view is not updated
* the route is considered to be a main route
* the view is a secondary view.

- the route has a `view` property, but a view is not named

* the view is not named
* the route is considered to be secondary
* the view is (the) main view and would update only for main routes

- the route has a `view` property and the view is named, but
the name does not match

* the view is not updated
* the view is secondary
* the route is secondary - it propably updates another view

- the route has a `view` property and the view is named with the same

* the view is updated regarding the template and the controller
associated with the route
* the route and view are secondary, but they are bound together

If the location is changed to a route which has a view attached, but
such view does not exist then AngularJS will do nothing and no view
will be updated.

Implementation
==============

The whole thing is happening in the `ngView` directive on
`$routeChangeSuccess` event. When the `update` function in
`ngView` is called the view is updated only if the current route
and the view match.

`$route.last` is set to the previous route when a named view is updated.
This could be used from a developer to recover the location to
a previous path corresponding to a main route.

For example if you have a modal dialog with its own url and a matching route,
when the dialog is closed you would want to recover the url to the location
of the previous main route.

`$route.interpolate()` is exposed so it could be used in such scenario to
build the path using `$route.last.params`.