angular - Angular2 detecting change in transclusion -
i'm working in new component implement dot navigation.
the parent container component called dotnavigationcomponent , each page dotnavigationpage. page selector created in dotnavigationcomponent want change page clicking on dots. i'm trying using transclusion.
import {component, eventemitter, contentchildren, oninit, aftercontentinit, optional, host, input, querylist, injectable } '@angular/core'; @component({ selector: 'dot-navigation-page', template: ` <ng-content *ngif="showing"></ng-content> `, }) export class dotnavigationpage implements aftercontentinit { @input("page") page:number; public changepage:eventemitter<any> = new eventemitter(); public showing:boolean = false; constructor() {} ngaftercontentinit() { if(this.page == 0){ this.showing = true; } this.changepage.subscribe((index)=>{ this.showing = false; if(this.page == index){ this.showing = true; } }) } } @component({ selector: 'dot-navigation', template: ` <div class="dot-navigation"> <ng-content></ng-content> </div> <div class="dot-navigation-scroll"> <span (click)="nextpage(page)" *ngfor="let page of numpages">o</span> </div> `, styles: [` .dot-navigation-scroll{ display: flex; justify-content: center; } `] }) export class dotnavigationcomponent implements aftercontentinit { public numpages:number[] = []; @contentchildren(dotnavigationpage) pages:querylist<dotnavigationpage> ; constructor(){} ngaftercontentinit(){ for(let = 0; < this.pages.length; i++){ this.numpages.push(i); } this.pages.foreach(page => { page.changepage.subscribe(()=>{console.log("test")}) }) } nextpage(index:number){ console.log(index); this.pages.foreach(p=>{ p.changepage.emit(index); }) } } @injectable() export class dotservice{ changepage:eventemitter<number> = new eventemitter<number>(); }
the problem pagecomponents not changing when change page. have try modify directly pagecomponents attributes.
any idea? thanks!
Comments
Post a Comment