Just having a bit of difficulty passing a router param (id) to an ngForm and then to an event emitter. Here is how I get the id - as you can see the first console.log works fine, i can get the id from the router. Now I am trying to assign this to my singleOpenHome object (but get an undefined error):
@Input() singleOpenHome: OpenHomeModel;
ngOnInit() {
// Get the slug on it from the router
this.route.params.forEach((params: Params) => {
let id = params['propertyID'];
console.log('id on the child is:'+id);
//this.singleOpenHome.propertyID == id; Cannot read property 'propertyID' of undefined
});
}
Now i am wanting to pass this to a form:
<form class="my2" #form="ngForm" (ngSubmit)="handleSubmit(form.value, form.valid)" novalidate></form>
Here is my event emmitter:
@Output()
update: EventEmitter<OpenHomeModel> = new EventEmitter<OpenHomeModel>();
constructor(private route: ActivatedRoute) {}
handleSubmit(sinlgeOpenHome: OpenHomeModel, isValid: boolean) {
if (isValid) {
this.update.emit(sinlgeOpenHome);
}
}
Any help appreciated
this.id = params['propertyID'];
— then you can access the property from anywhere in the component or its template.let id = ...
becomesthis.id = ...
. You'll also need to declare theid
property on the class.