feat(common): support as syntax in template/* bindings (#15025)

* feat(common): support `as` syntax in template/* bindings

Closes #15020

Showing the new and the equivalent old syntax.
- `*ngIf="exp as var1”`
   => `*ngIf="exp; let var1 = ngIf”`
- `*ngFor="var item of itemsStream |async as items”`
   => `*ngFor="var item of itemsStream |async; let items = ngForOf”`

* feat(common): convert ngIf to use `*ngIf="exp as local“` syntax

* feat(common): convert ngForOf to use `*ngFor=“let i of exp as local“` syntax

* feat(common): expose NgForOfContext and NgIfContext
This commit is contained in:
Miško Hevery
2017-03-14 20:46:29 -07:00
committed by Chuck Jazdzewski
parent 5fe2d8fd80
commit c10c060d20
12 changed files with 137 additions and 35 deletions

View File

@ -1334,6 +1334,18 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
expect(humanizeTplAst(parse('<div data-*ngIf="let a=b">', []))).toEqual(targetAst);
});
it('should parse variables via as ...', () => {
const targetAst = [
[EmbeddedTemplateAst],
[VariableAst, 'local', 'ngIf'],
[DirectiveAst, ngIf],
[BoundDirectivePropertyAst, 'ngIf', 'expr'],
[ElementAst, 'div'],
];
expect(humanizeTplAst(parse('<div *ngIf="expr as local">', [ngIf]))).toEqual(targetAst);
});
describe('directives', () => {
it('should locate directives in property bindings', () => {
const dirA =