Angular 7 : Build Prod Error: Property 'value' does not exist on type 'Component'

标签 angular typescript

我正在创建一个搜索输入。那个,也输入清除图标。

此错误仅针对 ng build --prod 缓存

错误是

ERROR in src\app\menu\sidebar\sidebar.component.html(4,88): : Property 'value' does not exist on type 'SidebarComponent'.
src\app\menu\sidebar\sidebar.component.html(5,28): : Property 'value' does not exist on type 'SidebarComponent'.
src\app\menu\sidebar\sidebar.component.html(4,88): : Property 'value' does not exist on type 'SidebarComponent'.


在我的 HTML 代码中

<h4 class="col my-2">Application List</h4>

<mat-form-field class="col">                
        <input class="search" matInput type="text"  placeholder="Search" [(ngModel)]="value" ><!--This is search input-->
        <button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
          <mat-icon>close</mat-icon>
        </button>
</mat-form-field>

<mat-list *ngFor="let app of applist" class="applist" #applist>    

            <a mat-list-item routerLink="." routerLinkActive="active">
                <mat-icon color="primary" class="mr-1">album</mat-icon>
                {{app}}
            </a>

    </mat-list>


为什么这个错误显示在--prod 上?

最佳答案

在组件中创建一个具有名称值的属性。生产构建还尝试查找未声明但在模板中使用的属性(因为编译无法捕获此错误),因此为什么会引发错误。

@Component({
   ...
})
export class SideBarComponent {
   ...
   value: any;
   ...
}

关于 Angular 7 : Build Prod Error: Property 'value' does not exist on type 'Component' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54365670/

相关文章:

typescript - typescript 中动态导入模块的类型/类是什么?

unit-testing - 带有可观察对象的单元测试模拟服务 => 订阅不是函数

html - 如何设计 Material 工具提示 Angular 7

angular - 在 Dart Angular2 中,如何根据事件组件更新站点标题标题?

javascript - 哪些场景我们要使用构造函数注入(inject)和spyon()注入(inject)?哪一个最好?

javascript - 带等待或不带返回之间有区别吗

angular - 在 Angular 2 中使用父组件中的子组件

Angular 通用 : How to create an app shell and only pre-render the shell?

angular - 扩展已注入(inject)服务的类而不在子类中重复注入(inject)器?

forms - 如何重置 ngFormModel 并丢失 Angular 2 Typescript 中的验证错误?