feat: ngIf now supports else; saves condition to local var
NgIf syntax has been extended to support else clause to display template when the condition is false. In addition the condition value can now be stored in local variable, for later reuse. This is especially useful when used with the `async` pipe. Example: ``` <div *ngIf="userObservable | async; else loading; let user"> Hello {{user.last}}, {{user.first}}! </div> <template #loading>Waiting...</template> ``` closes #13061 closes #13297
This commit is contained in:

committed by
Victor Berchet

parent
e15a3f273f
commit
b4db73d0bf
@ -213,7 +213,7 @@ export class UnknownTrackBy {
|
||||
'ng-if-cases.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({template: '<div ~{implicit}*ngIf="show; let l"~{implicit-end}>Showing now!</div>'})
|
||||
@Component({template: '<div ~{implicit}*ngIf="show; let l=unknown"~{implicit-end}>Showing now!</div>'})
|
||||
export class ShowIf {
|
||||
show = false;
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ describe('plugin', () => {
|
||||
expectSemanticError('app/ng-if-cases.ts', locationMarker, message);
|
||||
}
|
||||
it('should report an implicit context reference', () => {
|
||||
expectError('implicit', 'The template context does not have an implicit value');
|
||||
expectError('implicit', "The template context does not defined a member called 'unknown'");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user