简体   繁体   中英

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

This is my app.component.html code

<!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>

And the error I am getting is:

Failed to compile.

src/app/app.component.html:18:20 - error TS2339: Property 'DepScreen' does not exist on type 'AppComponent'.

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

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent. src/app/app.component.html:18:36 - error TS2339: Property 'EmpScreen' does not exist on type 'AppComponent'.

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

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent. src/app/app.component.html:22:20 - error TS2339: Property 'DepScreen' does not exist on type 'AppComponent'.

22 (click)="DepScreen=false;EmpScreen=true;">Employees ~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent. src/app/app.component.html:22:36 - error TS2339: Property 'EmpScreen' does not exist on type 'AppComponent'.

22 (click)="DepScreen=false;EmpScreen=true;">Employees ~~~~~~~~~

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent. src/app/app.component.html:27:28 - error TS2339: Property 'DepScreen' does not exist on type 'AppComponent'.

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

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent. src/app/app.component.html:28:26 - error TS2339: Property 'EmpScreen' does not exist on type 'AppComponent'.

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

src/app/app.component.ts:5:16 5 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.

What is the issue exactly and how can I solve it?

have you declared EmpScreen and DepScreen in your app.component.ts under Class AppComponent? Something like this: EmpScreen: boolean = false; DepScreen: boolean = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM