Reputation: 61
Im building simple angular application. and i get error on component(book-add) html.
<div class="form-group">
<label for="title"><span class="req">* </span> Title:</label>
<input required type="text" [(ngModel)]="book.title" name="title" id="title"
class="form-control phone" maxlength="28" placeholder="Enter book title..." />
</div>
Property 'title' does not exist on type 'Book'.
in book-add.component.ts i intialized Book class and by default it is showing i can enter title and author so that means it recognized Book class
book: Book=new Book("","");
this is class book.ts
export class Book{
constructor(
title:String,
author:String
){}
}
Why i am getting this error
Upvotes: 2
Views: 1627
Reputation: 62298
You are missing the access modifier which turns it into a field on the type. constructor( public title: string, public author:string){}
. Without that you are just passing in arguments that the code is completely ignoring.
export class Book{
constructor(
public title:String,
public author:String
){}
}
Upvotes: 6