簡體   English   中英

我在 angular:src/app/app.component.html:18:20 上收到此錯誤 - 錯誤 TS2339:“AppComponent”類型上不存在屬性“DepScreen”

[英]I am getting this error on angular:src/app/app.component.html:18:20 - error TS2339: Property 'DepScreen' does not exist on type 'AppComponent'

這是我的 app.component.html 代碼

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="container">
    <h3 class="d-flex justify-content-center">Angular 8 with Web API Demo</h3>
    <h5 class="d-flex justify-content-center">Employee Management Portal</h5>

    <nav class="navbar navbar-expand-sm bg-light navbar-dark">
      <ul class="navbar-nav">
        <li class="nav-item">
          <button class="m-1 btn btn-light btn-outline-primary" Button
          name="DepScreen"
          (click)="DepScreen=true; EmpScreen=false;">
          Department</button>
          <button class="m-1 btn btn-light btn-outline-primary" Button
          name="EmpScreen"
          (click)="DepScreen=false;EmpScreen=true;">Employees</button>

        </li>
      </ul>
    </nav>
    <app-department *ngIf="DepScreen"></app-department>
    <app-employee *ngIf="EmpScreen"></app-employee>

  </div>
</body>
</html>

我得到的錯誤是:

編譯失敗。

src/app/app.component.html:18:20 - 錯誤 TS2339:“AppComponent”類型上不存在屬性“DepScreen”。

18(點擊)="DepScreen=true; EmpScreen=false;">~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。 src/app/app.component.html:18:36 - 錯誤 TS2339:“AppComponent”類型上不存在“EmpScreen”屬性。

18(點擊)="DepScreen=true; EmpScreen=false;">~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。 src/app/app.component.html:22:20 - 錯誤 TS2339:“AppComponent”類型上不存在“DepScreen”屬性。

22(點擊)="DepScreen=false;EmpScreen=true;">員工~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。 src/app/app.component.html:22:36 - 錯誤 TS2339:“AppComponent”類型上不存在“EmpScreen”屬性。

22(點擊)="DepScreen=false;EmpScreen=true;">員工~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。 src/app/app.component.html:27:28 - 錯誤 TS2339:“AppComponent”類型上不存在“DepScreen”屬性。

27 <app-department *ngIf="DepScreen"> ~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。 src/app/app.component.html:28:26 - 錯誤 TS2339:“AppComponent”類型上不存在屬性“EmpScreen”。

28 <app-employee *ngIf="EmpScreen"> ~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~ 發生錯誤在組件 AppComponent 的模板中。

究竟是什么問題,我該如何解決?

您是否在 Class AppComponent 下的 app.component.ts 中聲明了 EmpScreen 和 DepScreen? 像這樣的東西: EmpScreen: boolean = false; DepScreen:boolean = 假;

暫無
暫無

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

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