feat(compiler): introduce <ng-template>
, deprecate <template>
and template
attribute
The rationale of this change is to improve the inter-operability with web components that might make use of the `<template>` tag. DEPRECATION The template tags and template attribute are deprecated: <template ngFor [ngFor]=items let-item><li>...</li></template> <li template="ngFor: let item of items">...</li> should be rewritten as: <ng-template ngFor [ngFor]=items let-item><li>...</li></ng-template> Note that they still be supported in 4.x with a deprecartion warning in development mode. MIGRATION - `template` tags (or elements with a `template` attribute) should be rewritten as a `ng-template` tag, - `ng-content` selectors should be updated to referto a `ng-template` where they use to refer to a template: `<ng-content selector="template[attr]">` should be rewritten as `<ng-content selector="ng-template[attr]">` - if you consume a component relying on your templates being actual `template` elements (that is they include a `<ng-content selector="template[attr]">`). You should still migrate to `ng-template` and make use of `ngProjectAs` to override the way `ng-content` sees the template: `<ng-template projectAs="template[attr]">` - while `template` elements are deprecated in 4.x they continue to work.
This commit is contained in:

committed by
Igor Minar

parent
3f519207a4
commit
bf8eb41248
@ -14,10 +14,10 @@ import {EmbeddedViewRef} from './view_ref';
|
||||
/**
|
||||
* Represents an Embedded Template that can be used to instantiate Embedded Views.
|
||||
*
|
||||
* You can access a `TemplateRef`, in two ways. Via a directive placed on a `<template>` element (or
|
||||
* directive prefixed with `*`) and have the `TemplateRef` for this Embedded View injected into the
|
||||
* constructor of the directive using the `TemplateRef` Token. Alternatively you can query for the
|
||||
* `TemplateRef` from a Component or a Directive via {@link Query}.
|
||||
* You can access a `TemplateRef`, in two ways. Via a directive placed on a `<ng-template>` element
|
||||
* (or directive prefixed with `*`) and have the `TemplateRef` for this Embedded View injected into
|
||||
* the constructor of the directive using the `TemplateRef` Token. Alternatively you can query for
|
||||
* the `TemplateRef` from a Component or a Directive via {@link Query}.
|
||||
*
|
||||
* To instantiate Embedded Views based on a Template, use
|
||||
* {@link ViewContainerRef#createEmbeddedView}, which will create the View and attach it to the
|
||||
|
@ -57,7 +57,7 @@ export abstract class ViewRef extends ChangeDetectorRef {
|
||||
* ```
|
||||
* Count: {{items.length}}
|
||||
* <ul>
|
||||
* <template ngFor let-item [ngForOf]="items"></template>
|
||||
* <ng-template ngFor let-item [ngForOf]="items"></ng-template>
|
||||
* </ul>
|
||||
* ```
|
||||
*
|
||||
@ -74,7 +74,7 @@ export abstract class ViewRef extends ChangeDetectorRef {
|
||||
* <!-- ViewRef: outer-0 -->
|
||||
* Count: 2
|
||||
* <ul>
|
||||
* <template view-container-ref></template>
|
||||
* <ng-template view-container-ref></ng-template>
|
||||
* <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
|
||||
* <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
|
||||
* </ul>
|
||||
|
@ -10,10 +10,8 @@ export enum ViewType {
|
||||
// A view that contains the host element with bound component directive.
|
||||
// Contains a COMPONENT view
|
||||
HOST,
|
||||
// The view of the component
|
||||
// Can contain 0 to n EMBEDDED views
|
||||
// The view of the component can contain 0 to n EMBEDDED views
|
||||
COMPONENT,
|
||||
// A view that is embedded into another View via a <template> element
|
||||
// inside of a COMPONENT view
|
||||
// A view is embedded into another View via a <ng-template> element inside of a COMPONENT view
|
||||
EMBEDDED
|
||||
}
|
||||
|
Reference in New Issue
Block a user