Angular
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
}<br />
}<br />
@NgModule({<br />
imports: [CommonModule],<br />
exports: [],<br />
declarations: [DataListComponent, PagerComponent],<br />
providers: [DataListService],<br />
})<br />
export class DataListModule { }<br />
PagerComponent lists all the page numbers. We set click event on each of them so we can let the parent know<br />
about the clicked page number.<br />
import { Component, Input, Output, EventEmitter } from '@angular/core';<br />
@Component({<br />
selector: 'pager',<br />
template: `<br />
<br />
{{page}}<br />
<br />
`<br />
})<br />
export class PagerComponent {<br />
@Input() pageCount: number;<br />
@Output() pageNumberClicked = new EventEmitter();<br />
constructor() { }<br />
}<br />
pageClicked(pageNum){<br />
this.pageNumberClicked.emit(pageNum); //Send clicked page number as output<br />
}<br />
Section 9.3: Parent - Child interaction using ViewChild<br />
Viewchild offers one way interaction from parent to child. There is no feedback or output from child when<br />
ViewChild is used.<br />
We have a DataListComponent that shows some information. DataListComponent has PagerComponent as it's<br />
child. When user makes a search on DataListComponent, it gets a data from a service and ask PagerComponent to<br />
refresh paging layout based on new number of pages.<br />
import { Component, NgModule, ViewChild } from '@angular/core';<br />
import { CommonModule } from '@angular/common';<br />
import { DataListService } from './dataList.service';<br />
import { PagerComponent } from './pager.component';<br />
@Component({<br />
selector: 'datalist',<br />
template: `<br />
Search<br />
<br />
<br />
{{person.name}}<br />
{{person.surname}}<br />
<br />
<br />
GoalKicker.com – <strong>Angular</strong> 2 Notes for Professionals 48