1
1
// #docregion
2
- import { Component , Input , AfterViewInit , ViewChild , ComponentFactoryResolver , OnDestroy } from '@angular/core' ;
2
+ import { Component , Input , OnInit , ViewChild , ComponentFactoryResolver , OnDestroy } from '@angular/core' ;
3
3
4
4
import { AdDirective } from './ad.directive' ;
5
5
import { AdItem } from './ad-item' ;
6
6
import { AdComponent } from './ad.component' ;
7
7
8
8
@Component ( {
9
- selector : 'app-add -banner' ,
9
+ selector : 'app-ad -banner' ,
10
10
// #docregion ad-host
11
11
template : `
12
12
<div class="ad-banner">
@@ -17,16 +17,15 @@ import { AdComponent } from './ad.component';
17
17
// #enddocregion ad-host
18
18
} )
19
19
// #docregion class
20
- export class AdBannerComponent implements AfterViewInit , OnDestroy {
20
+ export class AdBannerComponent implements OnInit , OnDestroy {
21
21
@Input ( ) ads : AdItem [ ] ;
22
- currentAddIndex : number = - 1 ;
22
+ currentAdIndex : number = - 1 ;
23
23
@ViewChild ( AdDirective ) adHost : AdDirective ;
24
- subscription : any ;
25
24
interval : any ;
26
25
27
26
constructor ( private componentFactoryResolver : ComponentFactoryResolver ) { }
28
27
29
- ngAfterViewInit ( ) {
28
+ ngOnInit ( ) {
30
29
this . loadComponent ( ) ;
31
30
this . getAds ( ) ;
32
31
}
@@ -36,8 +35,8 @@ export class AdBannerComponent implements AfterViewInit, OnDestroy {
36
35
}
37
36
38
37
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 ] ;
41
40
42
41
let componentFactory = this . componentFactoryResolver . resolveComponentFactory ( adItem . component ) ;
43
42
0 commit comments