Skip to content

Commit c82cef8

Browse files
kapunahelewongalexeagle
authored andcommitted
docs: fix dynamic component loader example (angular#22181)
closes angular#21903 PR Close angular#22181
1 parent f8749bf commit c82cef8

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// #docregion
2-
import { Component, Input, AfterViewInit, ViewChild, ComponentFactoryResolver, OnDestroy } from '@angular/core';
2+
import { Component, Input, OnInit, ViewChild, ComponentFactoryResolver, OnDestroy } from '@angular/core';
33

44
import { AdDirective } from './ad.directive';
55
import { AdItem } from './ad-item';
66
import { AdComponent } from './ad.component';
77

88
@Component({
9-
selector: 'app-add-banner',
9+
selector: 'app-ad-banner',
1010
// #docregion ad-host
1111
template: `
1212
<div class="ad-banner">
@@ -17,16 +17,15 @@ import { AdComponent } from './ad.component';
1717
// #enddocregion ad-host
1818
})
1919
// #docregion class
20-
export class AdBannerComponent implements AfterViewInit, OnDestroy {
20+
export class AdBannerComponent implements OnInit, OnDestroy {
2121
@Input() ads: AdItem[];
22-
currentAddIndex: number = -1;
22+
currentAdIndex: number = -1;
2323
@ViewChild(AdDirective) adHost: AdDirective;
24-
subscription: any;
2524
interval: any;
2625

2726
constructor(private componentFactoryResolver: ComponentFactoryResolver) { }
2827

29-
ngAfterViewInit() {
28+
ngOnInit() {
3029
this.loadComponent();
3130
this.getAds();
3231
}
@@ -36,8 +35,8 @@ export class AdBannerComponent implements AfterViewInit, OnDestroy {
3635
}
3736

3837
loadComponent() {
39-
this.currentAddIndex = (this.currentAddIndex + 1) % this.ads.length;
40-
let adItem = this.ads[this.currentAddIndex];
38+
this.currentAdIndex = (this.currentAdIndex + 1) % this.ads.length;
39+
let adItem = this.ads[this.currentAdIndex];
4140

4241
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(adItem.component);
4342

aio/content/examples/dynamic-component-loader/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AdItem } from './ad-item';
88
selector: 'app-root',
99
template: `
1010
<div>
11-
<app-add-banner [ads]="ads"></app-add-banner>
11+
<app-ad-banner [ads]="ads"></app-ad-banner>
1212
</div>
1313
`
1414
})

aio/content/guide/dynamic-component-loader.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ Take it step by step. First, it picks an ad.
109109

110110
The `loadComponent()` method chooses an ad using some math.
111111

112-
First, it sets the `currentAddIndex` by taking whatever it
112+
First, it sets the `currentAdIndex` by taking whatever it
113113
currently is plus one, dividing that by the length of the `AdItem` array, and
114-
using the _remainder_ as the new `currentAddIndex` value. Then, it uses that
114+
using the _remainder_ as the new `currentAdIndex` value. Then, it uses that
115115
value to select an `adItem` from the array.
116116

117117

0 commit comments

Comments
 (0)