I have created a simple filtering app that works, when I have the filtering and the listing in the same component (app.ts): http://plnkr.co/0eEIJg5uzL6KsI70wWsC
@Component({
selector: 'my-app',
template: `
<select name="selectmake" [(ngModel)]="makeListFilter" (ngModelChange)="selectMake()">
<option *ngFor="let muscleCar of muscleCars" [ngValue]="muscleCar">{{muscleCar.name}}</option>
</select>
<select name="selectmodel" [(ngModel)]="modelListFilter">
<option *ngFor="let m of makeListFilter?.models" [ngValue]="m.model">{{m['model']}}</option>
</select>
<button class="btn btn-default" type="submit" (click)="searchCars()">FILTER</button>
<ul>
<li *ngFor="let _car of _cars | makeFilter:makeSearch | modelFilter:modelSearch">
<h2>{{_car.id}} {{_car.carMake}} {{_car.carModel}}</h2>
</li>
</ul>`,
providers: [ AppService ]
})
export class App implements OnInit {
makeListFilter: Object[];
modelListFilter: string = '';
_cars: ICar[];
constructor(private _appService: AppService) { }
ngOnInit(): void {
this._appService.getCars()
.subscribe(_cars => this._cars = _cars);
}
selectMake() {
if(this.modelListFilter) {
this.modelListFilter = '';
}
}
searchCars() {
this.makeSearch = this.makeListFilter['name'];
this.modelSearch = this.modelListFilter;
}
What I would like to achieve is to move the filtering into its own component (filtering.component.ts) and pass the values of the select boxes back to the listing component (app.ts) using @Input and @Output functions appropriately.
I've already separated the components here, but I cannot get the data passed to the listing component. (app.ts): http://plnkr.co/1ZEf1efXOBysGndOnKM5
Thanks in advance.