Matovina Igor
Matovina Igor

Reputation: 61

Property does not exist on type Class and components angular

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

Answers (1)

Igor
Igor

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

Related Questions