@ -11,7 +11,7 @@ import {Component, ContentChild, Directive, Input} from '@angular/core';
|
||||
|
||||
@Directive({selector: 'pane'})
|
||||
export class Pane {
|
||||
@Input() id !: string;
|
||||
@Input() id!: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -21,7 +21,7 @@ export class Pane {
|
||||
`
|
||||
})
|
||||
export class Tab {
|
||||
@ContentChild(Pane) pane !: Pane;
|
||||
@ContentChild(Pane) pane!: Pane;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -38,6 +38,8 @@ export class Tab {
|
||||
export class ContentChildComp {
|
||||
shouldShow = true;
|
||||
|
||||
toggle() { this.shouldShow = !this.shouldShow; }
|
||||
toggle() {
|
||||
this.shouldShow = !this.shouldShow;
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
@ -15,7 +15,7 @@ class ChildDirective {
|
||||
|
||||
@Directive({selector: 'someDir'})
|
||||
class SomeDir implements AfterContentInit {
|
||||
@ContentChild(ChildDirective) contentChild !: ChildDirective;
|
||||
@ContentChild(ChildDirective) contentChild!: ChildDirective;
|
||||
|
||||
ngAfterContentInit() {
|
||||
// contentChild is set
|
||||
|
@ -6,7 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ElementFinder, browser, by, element} from 'protractor';
|
||||
import {browser, by, element, ElementFinder} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../../test-utils';
|
||||
|
||||
describe('contentChild example', () => {
|
||||
|
@ -11,7 +11,7 @@ import {Component, ContentChildren, Directive, Input, QueryList} from '@angular/
|
||||
|
||||
@Directive({selector: 'pane'})
|
||||
export class Pane {
|
||||
@Input() id !: string;
|
||||
@Input() id!: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -22,8 +22,8 @@ export class Pane {
|
||||
`
|
||||
})
|
||||
export class Tab {
|
||||
@ContentChildren(Pane) topLevelPanes !: QueryList<Pane>;
|
||||
@ContentChildren(Pane, {descendants: true}) arbitraryNestedPanes !: QueryList<Pane>;
|
||||
@ContentChildren(Pane) topLevelPanes!: QueryList<Pane>;
|
||||
@ContentChildren(Pane, {descendants: true}) arbitraryNestedPanes!: QueryList<Pane>;
|
||||
|
||||
get serializedPanes(): string {
|
||||
return this.topLevelPanes ? this.topLevelPanes.map(p => p.id).join(', ') : '';
|
||||
@ -53,6 +53,8 @@ export class Tab {
|
||||
export class ContentChildrenComp {
|
||||
shouldShow = false;
|
||||
|
||||
show() { this.shouldShow = true; }
|
||||
show() {
|
||||
this.shouldShow = true;
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
@ -15,7 +15,7 @@ class ChildDirective {
|
||||
|
||||
@Directive({selector: 'someDir'})
|
||||
class SomeDir implements AfterContentInit {
|
||||
@ContentChildren(ChildDirective) contentChildren !: QueryList<ChildDirective>;
|
||||
@ContentChildren(ChildDirective) contentChildren!: QueryList<ChildDirective>;
|
||||
|
||||
ngAfterContentInit() {
|
||||
// contentChildren is set
|
||||
|
@ -6,7 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ElementFinder, browser, by, element} from 'protractor';
|
||||
import {browser, by, element, ElementFinder} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../../test-utils';
|
||||
|
||||
describe('contentChildren example', () => {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectFlags, InjectionToken, Injector, Type, inject, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
|
||||
import {inject, InjectFlags, InjectionToken, Injector, Type, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
|
||||
|
||||
class MockRootScopeInjector implements Injector {
|
||||
constructor(readonly parent: Injector) {}
|
||||
|
@ -59,9 +59,8 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
}
|
||||
|
||||
const injector = Injector.create({
|
||||
providers: [
|
||||
{provide: NeedsService, deps: [UsefulService]}, {provide: UsefulService, deps: []}
|
||||
]
|
||||
providers:
|
||||
[{provide: NeedsService, deps: [UsefulService]}, {provide: UsefulService, deps: []}]
|
||||
});
|
||||
expect(injector.get(NeedsService).service instanceof UsefulService).toBe(true);
|
||||
// #enddocregion
|
||||
@ -104,7 +103,9 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
@Injectable()
|
||||
class NeedsDependency {
|
||||
constructor(@SkipSelf() public dependency: Dependency) { this.dependency = dependency; }
|
||||
constructor(@SkipSelf() public dependency: Dependency) {
|
||||
this.dependency = dependency;
|
||||
}
|
||||
}
|
||||
|
||||
const parent = Injector.create({providers: [{provide: Dependency, deps: []}]});
|
||||
@ -158,7 +159,7 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
declarations: [App, ParentCmp, ChildDirective],
|
||||
});
|
||||
|
||||
let cmp: ComponentFixture<App> = undefined !;
|
||||
let cmp: ComponentFixture<App> = undefined!;
|
||||
expect(() => cmp = TestBed.createComponent(App)).not.toThrow();
|
||||
|
||||
expect(cmp.debugElement.children[0].children[0].injector.get(ChildDirective).logs).toEqual([
|
||||
@ -167,6 +168,5 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ import {Injectable, InjectionToken, Injector, Optional, ReflectiveInjector} from
|
||||
describe('ClassProvider', () => {
|
||||
it('works', () => {
|
||||
// #docregion ClassProvider
|
||||
abstract class Shape { name !: string; }
|
||||
abstract class Shape {
|
||||
name!: string;
|
||||
}
|
||||
|
||||
class Square extends Shape {
|
||||
name = 'square';
|
||||
@ -92,7 +94,9 @@ import {Injectable, InjectionToken, Injector, Optional, ReflectiveInjector} from
|
||||
describe('StaticClassProvider', () => {
|
||||
it('works', () => {
|
||||
// #docregion StaticClassProvider
|
||||
abstract class Shape { name !: string; }
|
||||
abstract class Shape {
|
||||
name!: string;
|
||||
}
|
||||
|
||||
class Square extends Shape {
|
||||
name = 'square';
|
||||
@ -200,6 +204,5 @@ import {Injectable, InjectionToken, Injector, Optional, ReflectiveInjector} from
|
||||
// #enddocregion
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ElementFinder, browser, by, element} from 'protractor';
|
||||
import {browser, by, element, ElementFinder} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../../test-utils';
|
||||
|
||||
describe('viewChild example', () => {
|
||||
|
@ -11,7 +11,7 @@ import {Component, Directive, Input, ViewChild} from '@angular/core';
|
||||
|
||||
@Directive({selector: 'pane'})
|
||||
export class Pane {
|
||||
@Input() id !: string;
|
||||
@Input() id!: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -28,10 +28,14 @@ export class Pane {
|
||||
export class ViewChildComp {
|
||||
@ViewChild(Pane)
|
||||
set pane(v: Pane) {
|
||||
setTimeout(() => { this.selectedPane = v.id; }, 0);
|
||||
setTimeout(() => {
|
||||
this.selectedPane = v.id;
|
||||
}, 0);
|
||||
}
|
||||
selectedPane: string = '';
|
||||
shouldShow = true;
|
||||
toggle() { this.shouldShow = !this.shouldShow; }
|
||||
toggle() {
|
||||
this.shouldShow = !this.shouldShow;
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
@ -15,7 +15,7 @@ class ChildDirective {
|
||||
|
||||
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
|
||||
class SomeCmp implements AfterViewInit {
|
||||
@ViewChild(ChildDirective) child !: ChildDirective;
|
||||
@ViewChild(ChildDirective) child!: ChildDirective;
|
||||
|
||||
ngAfterViewInit() {
|
||||
// child is set
|
||||
|
@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
|
||||
import {ElementFinder, browser, by, element} from 'protractor';
|
||||
import {browser, by, element, ElementFinder} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../../test-utils';
|
||||
|
||||
describe('viewChildren example', () => {
|
||||
|
@ -11,7 +11,7 @@ import {AfterViewInit, Component, Directive, Input, QueryList, ViewChildren} fro
|
||||
|
||||
@Directive({selector: 'pane'})
|
||||
export class Pane {
|
||||
@Input() id !: string;
|
||||
@Input() id!: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -27,20 +27,26 @@ export class Pane {
|
||||
`,
|
||||
})
|
||||
export class ViewChildrenComp implements AfterViewInit {
|
||||
@ViewChildren(Pane) panes !: QueryList<Pane>;
|
||||
@ViewChildren(Pane) panes!: QueryList<Pane>;
|
||||
serializedPanes: string = '';
|
||||
|
||||
shouldShow = false;
|
||||
|
||||
show() { this.shouldShow = true; }
|
||||
show() {
|
||||
this.shouldShow = true;
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.calculateSerializedPanes();
|
||||
this.panes.changes.subscribe((r) => { this.calculateSerializedPanes(); });
|
||||
this.panes.changes.subscribe((r) => {
|
||||
this.calculateSerializedPanes();
|
||||
});
|
||||
}
|
||||
|
||||
calculateSerializedPanes() {
|
||||
setTimeout(() => { this.serializedPanes = this.panes.map(p => p.id).join(', '); }, 0);
|
||||
setTimeout(() => {
|
||||
this.serializedPanes = this.panes.map(p => p.id).join(', ');
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
@ -15,7 +15,7 @@ class ChildDirective {
|
||||
|
||||
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
|
||||
class SomeCmp implements AfterViewInit {
|
||||
@ViewChildren(ChildDirective) viewChildren !: QueryList<ChildDirective>;
|
||||
@ViewChildren(ChildDirective) viewChildren!: QueryList<ChildDirective>;
|
||||
|
||||
ngAfterViewInit() {
|
||||
// viewChildren is set
|
||||
|
Reference in New Issue
Block a user