小编nmt*_*nmt的帖子

在 Angular 模板中使用属性绑定时,类型“string”不可分配给类型“number”

出现以下错误:

Error: src/app/pages/journal-list/journal-list.component.html:27:23 - error TS2322: Type 'string' is not assignable to type 'number'.
    
    27 [title]="entry.title" [date]="entry.date"
                             ~~~~~~~~~~~~~~~~~~~
    
      src/app/pages/journal-list/journal-list.component.ts:7:16
        7   templateUrl: './journal-list.component.html',
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Error occurs in the template of component JournalListComponent.
    src/app/pages/journal-list/journal-list.component.html:26:1 - error TS2322: Type 'number' is not assignable to type 'string | any[] | null | undefined'.
    
    26 [routerLink] ="i"
       ~~~~~~~~~~~~~~~~~
    
      src/app/pages/journal-list/journal-list.component.ts:7:16
        7   templateUrl: './journal-list.component.html',
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Error occurs in the template of component JournalListComponent.
Run Code Online (Sandbox Code Playgroud)

显然是因为我正在使用属性绑定 [date]="entry.date"。我已将财产日期声明为数字。为什么会出现这种情况?

上下文的代码片段:

 <div class="entries-list">
<app-journal-entry *ngFor="let entry of entries; index as i"
[routerLink] …
Run Code Online (Sandbox Code Playgroud)

typescript angular

8
推荐指数
1
解决办法
7723
查看次数

标签 统计

angular ×1

typescript ×1