-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
397 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
modules/@angular/examples/common/ngIf/ts/e2e_test/ngIf_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {$, ExpectedConditions, browser, by, element} from 'protractor'; | ||
import {verifyNoBrowserErrors} from '../../../../_common/e2e_util'; | ||
|
||
function waitForElement(selector: string) { | ||
const EC = ExpectedConditions; | ||
// Waits for the element with id 'abc' to be present on the dom. | ||
browser.wait(EC.presenceOf($(selector)), 20000); | ||
} | ||
|
||
describe('ngIf', () => { | ||
const URL = 'common/ngIf/ts/'; | ||
afterEach(verifyNoBrowserErrors); | ||
|
||
describe('ng-if-simple', () => { | ||
var comp = 'ng-if-simple' | ||
it('should hide/show content', () => { | ||
browser.get(URL); | ||
waitForElement(comp); | ||
expect(element.all(by.css(comp)).get(0).getText()).toEqual('hide show = true\nText to show'); | ||
element(by.css(comp + ' button')).click(); | ||
expect(element.all(by.css(comp)).get(0).getText()).toEqual('show show = false'); | ||
}); | ||
}); | ||
|
||
describe('ng-if-else', () => { | ||
var comp = 'ng-if-else' | ||
it('should hide/show content', () => { | ||
browser.get(URL); | ||
waitForElement(comp); | ||
expect(element.all(by.css(comp)).get(0).getText()).toEqual('hide show = true\nText to show'); | ||
element(by.css(comp + ' button')).click(); | ||
expect(element.all(by.css(comp)).get(0).getText()) | ||
.toEqual('show show = false\nAlternate text while primary text is hidden'); | ||
}); | ||
}); | ||
|
||
describe('ng-if-then-else', () => { | ||
var comp = 'ng-if-then-else' | ||
it('should hide/show content', () => { | ||
browser.get(URL); | ||
waitForElement(comp); | ||
expect(element.all(by.css(comp)).get(0).getText()) | ||
.toEqual('hide Switch Primary show = true\nPrimary text to show'); | ||
element.all(by.css(comp + ' button')).get(1).click(); | ||
expect(element.all(by.css(comp)).get(0).getText()) | ||
.toEqual('hide Switch Primary show = true\nSecondary text to show'); | ||
element.all(by.css(comp + ' button')).get(0).click(); | ||
expect(element.all(by.css(comp)).get(0).getText()) | ||
.toEqual('show Switch Primary show = false\nAlternate text while primary text is hidden'); | ||
}); | ||
}); | ||
|
||
describe('ng-if-let', () => { | ||
var comp = 'ng-if-let' | ||
it('should hide/show content', () => { | ||
browser.get(URL); | ||
waitForElement(comp); | ||
expect(element.all(by.css(comp)).get(0).getText()) | ||
.toEqual('Next User\nWaiting... (user is null)'); | ||
element(by.css(comp + ' button')).click(); | ||
expect(element.all(by.css(comp)).get(0).getText()).toEqual('Next User\nHello Smith, John!'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.