Struggling to pass a router param (id) to an ngForm and then to an event emitter. I am able to retrieve the id from the router successfully, but when trying to assign it to my singleOpenHome object, I encounter 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 want to pass this to a form:
<form class="my2" #form="ngForm" (ngSubmit)="handleSubmit(form.value, form.valid)" novalidate></form>
Event emitter for submitting the form:
@Output()
update: EventEmitter<OpenHomeModel> = new EventEmitter<OpenHomeModel>();
constructor(private route: ActivatedRoute) {}
handleSubmit(sinlgeOpenHome: OpenHomeModel, isValid: boolean) {
if (isValid) {
this.update.emit(sinlgeOpenHome);
}
}
Any assistance would be greatly appreciated.