簡體   English   中英

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

[英]Property 'title' does not exist on type 'never'

在我的代碼中,HTML 文件的標題和內容中出現了兩個錯誤。 我想輸入帖子項目並將它們顯示在列表中。

“從不”類型上不存在屬性“title”。 “從不”類型上不存在屬性“內容”。

<ngb-accordion #acc="ngbAccordion" *ngFor="let post of posts">
  <ngb-panel id="toggle-1" title="{{post.title}}" >
    <ng-template ngbPanelContent>
      {{post.content}}
    </ng-template>
  </ngb-panel>
</ngb-accordion>

這是 ts 文件

import { Component, OnInit } from '@angular/core';



@Component({
  selector: 'app-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {


content ="";
  etitle = "";
  elist = "";
  posts = [];

  onaddlist() {
    const posts = {
      title: this.etitle,
      content: this.elist
    };

  }



  constructor() { }

  ngOnInit(): void {
  }

}

title屬性只有一種用法: post.title 這意味着posts數組元素之一是never never是不可達塊的指示符。 我敢肯定,如果您為this.posts添加了正確的this.posts ,編譯器會指出一個問題。

暫無
暫無

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

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