簡體   English   中英

類型 Class 和組件 angular 上不存在屬性

[英]Property does not exist on type Class and components angular

我正在構建簡單的 angular 應用程序。 我在組件(書籍添加)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>

“書”類型上不存在屬性“標題”。

在 book-add.component.ts 我初始化了 Book class 並且默認情況下它顯示我可以輸入標題和作者,這意味着它識別了 Book class

book: Book=new Book("","");

這是 class book.ts

export class Book{
    constructor(
        title:String,
        author:String
    ){}
}

為什么我收到此錯誤

您缺少將其轉換為類型字段的訪問修飾符。 constructor( public title: string, public author:string){} 沒有它,您只是傳入代碼完全忽略的 arguments。

export class Book{
    constructor(
        public title:String,
        public author:String
    ){}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM