feat($route): rename template -> tempalteUrl and add support for inline templates

BREAKING CHANGE: template in $route definition is now templateUrl
To migrate just rename `template` to `templateUrl`.
This commit is contained in:
Misko Hevery
2012-05-17 16:36:18 -07:00
parent 7c24282188
commit 0a6e464a93
7 changed files with 113 additions and 86 deletions

View File

@@ -49,11 +49,11 @@
<file name="script.js">
angular.module('ngView', [], function($routeProvider, $locationProvider) {
$routeProvider.when('/Book/:bookId', {
template: 'book.html',
templateUrl: 'book.html',
controller: BookCntl
});
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
template: 'chapter.html',
templateUrl: 'chapter.html',
controller: ChapterCntl
});

View File

@@ -29,9 +29,12 @@ function $RouteProvider(){
*
* - `controller` `{function()=}` Controller fn that should be associated with newly
* created scope.
* - `template` `{string=}` path to an html template that should be used by
* - `template` `{string=}` html template as a string that should be used by
* {@link angular.module.ng.$compileProvider.directive.ngView ngView} or
* {@link angular.module.ng.$compileProvider.directive.ngInclude ngInclude} directives.
* this property takes precedence over `templateUrl`.
* - `templateUrl` `{string=}` path to an html template that should be used by
* {@link angular.module.ng.$compileProvider.directive.ngView ngView}.
* - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
* be injected into the controller. If any of these dependencies are promises, they will be
* resolved and converted to a value before the controller is instantiated and the
@@ -49,7 +52,7 @@ function $RouteProvider(){
* If `redirectTo` is a function, it will be called with the following parameters:
*
* - `{Object.<string>}` - route parameters extracted from the current
* `$location.path()` by applying the current route template.
* `$location.path()` by applying the current route templateUrl.
* - `{string}` - current `$location.path()`
* - `{Object}` - current `$location.search()`
*
@@ -152,7 +155,7 @@ function $RouteProvider(){
<hr />
<pre>$location.path() = {{$location.path()}}</pre>
<pre>$route.current.template = {{$route.current.template}}</pre>
<pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
<pre>$route.current.params = {{$route.current.params}}</pre>
<pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
<pre>$routeParams = {{$routeParams}}</pre>
@@ -173,7 +176,7 @@ function $RouteProvider(){
<file name="script.js">
angular.module('ngView', [], function($routeProvider, $locationProvider) {
$routeProvider.when('/Book/:bookId', {
template: 'book.html',
templateUrl: 'book.html',
controller: BookCntl,
resolve: {
// I will cause a 1 second delay
@@ -185,7 +188,7 @@ function $RouteProvider(){
}
});
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
template: 'chapter.html',
templateUrl: 'chapter.html',
controller: ChapterCntl
});
@@ -365,17 +368,21 @@ function $RouteProvider(){
then(function() {
if (next) {
var keys = [],
values = [];
values = [],
template;
forEach(next.resolve || {}, function(value, key) {
keys.push(key);
values.push(isFunction(value) ? $injector.invoke(value) : $injector.get(value));
});
if (next.template) {
if (isDefined(template = next.template)) {
} else if (isDefined(template = next.templateUrl)) {
template = $http.get(template, {cache: $templateCache}).
then(function(response) { return response.data; });
}
if (isDefined(template)) {
keys.push('$template');
values.push($http.
get(next.template, {cache: $templateCache}).
then(function(response) { return response.data; }));
values.push(template);
}
return $q.all(values).then(function(values) {
var locals = {};