Trying to establish a connection between a Company object in my component and the view has proved to be more challenging than expected. While I didn't encounter any issues doing this in AngularJS, attempting it in Angular 2 resulted in an error.
View
<input type="text" class="form-control" [(ngModel)]="company.name"
placeholder="Company Name" required>
<input type="text" class="form-control" [(ngModel)]="company.address1"
placeholder="Address Line 1" id="address1" required>
<button class="btn btn-primary pull-right next-btn" (click)="show()">Next</button>
Component:
company: Company;
constructor(
private router: Router
) { }
ngOnInit() { }
show() {
console.log(this.company);
}
Error Message:
TypeError: Cannot read property 'name' of undefined