I want to bind a Company object from my component to my view. This was easy in AngularJS, but I get an error when I do this in Angular 2.
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:
TypeError: Cannot read property 'name' of undefined