javascript - AppComponent 类型上不存在 Angular 8 属性
问题描述
我创建了一个小应用程序,Angular 8
它只是一个带有 2 个选择器的应用程序。但它Property 'DepScreen' does not exist on type 'AppComponent'
在编译时抛出错误。
请在下面详细查找错误。
ERROR in src/app/app.component.html:10:20 - error TS2339: Property 'DepScreen' does not exist on type 'AppComponent'.
10 (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:10:36 - error TS2339: Property 'EmpScreen' does not exist on type 'AppComponent'.
10 (click) = "DepScreen=true; EmpScreen=false;">
~~~~~~~~~
请在下面找到 index.html 代码
<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
label = "DepScreen"
(click) = "DepScreen=true; EmpScreen=false;">
Departments
</button>
</li>
<li class="nav-item">
<button class="m-1 btn btn-light btn-outline-primary" Button
label = "EmpScreen"
(click) = "DepScreen=false; EmpScreen=true;">
Employees
</button>
</li>
</ul>
</nav>
<app-department *ngIf="DepScreen"></app-department>
<app-employee *ngIf="EmpScreen"></app-employee>
请找到我的 app.component.ts 文件
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Hello World';
}
解决方案
索引.html
<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
label = "DepScreen"
(click) = "onScreenSelect()">
Departments
</button>
</li>
<li class="nav-item">
<button class="m-1 btn btn-light btn-outline-primary" Button
label = "EmpScreen"
(click) = "onScreenSelect()">
Employees
</button>
</li>
</ul>
</nav>
现在,在你的 app.component.ts
export class AppComponent {
title = 'Hello World';
DepScreen = true; // put the default values
EmpScreen = false;
onScreenSelect(){
this.DepScreen = !this.DepScreen; // at any point in time only one screen is visible
this.EmpScreen = !this.EmpScreen;
}
}
推荐阅读
- angular - Angular 构建找不到具有相对路径的模块(在 azure dev ops 上)
- python - 如何在 Python 3 中计算特定质心(k 均值聚类)的协方差矩阵?
- python - DataFrame 到 sql 语句?
- python - 如何检测 Python 线程是否被杀死?
- php - 我的 php 不能正常工作,我可以找到问题
- javascript - 如何将日期数组压缩到他们的月份?
- sql - 调整重叠日期并应用其他规则
- ruby - 如何在 SublimeREPL 中修复“可能会发现'pry error'”
- ionic-framework - Ionic VS Code 调试问题:无法与目标通信
- java - 寻找日期格式的最佳正则表达式模式