Adding Navigation With Event Binding and Ngif
Adding Navigation With Event Binding and Ngif
STEPS
***********
we access the property where we stored the EventEmitter and use the emit method
and pass in our
method's parammeter called feature.
***********
import { Output } from '@angular/core';
import { EventEmitter } from 'events';
onSelect(feature: string) {
this.featureSelected.emit(feature);
}
************
<app-header (featureSelected)="onNavigate($event)"></app-header>
4. in app.component.ts
Let's define our method.
we pass in feature property with type of string but it could be any property
name.
why feature property, remember our goal to click our feature link which is the
recipe and shoppiing list link?
then we have initiated a property with value of a default feature which
'recipe'
Then we access our loaddedFeature property and we assign our feature parameter.
***********
loadedFeature = "recipe"
onNavigate(feature: string) {
this.loadedFeature = feature;
}
5. in app.component.html
Now we can use ngIf which of the below compooent can be dispalyed.
<app-recipes></app-recipes>
<app-shopping-list></app-shopping-list>
******************
*****************************************************
ERRORS
@Output() featureSelected
SOLUTION
Imported EventEmitter from angular/core