简体   繁体   English

2.0.0版本无法绑定到'ngIf',因为它不是'div'的已知属性

[英]2.0.0 version Can't bind to 'ngIf' since it isn't a known property of 'div'

I am getting an error on the *ngIf any ideas what could be wrong? 我在* ngIf上出现错误任何想法可能出错? I am using latest version (2.0.0) of Angular 2. 我正在使用Angular 2的最新版本(2.0.0)。

Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngIf' since it isn't a known property of 'div'. ("
</div>
</div>
<div class='row' [ERROR ->]*ngIf='listFilter'>
<div class='col-md-6'>
<h3>Filtered by: {{ listFilter"): EventlogComponent@12:25
Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "directives" section. ("
</div>

Here it is my HTML I have the listFilter defined in the Component.ts below 这是我的HTML我在下面的Component.ts中定义了listFilter

<div class='panel panel-primary'>
    <div class='panel-heading'>
        {{ pageTitle }}
    </div>

    <!-- Filter the eventlogs   -->
    <div class='panel-body'>
        <div class='row'>
            <div class='col-md-2'>Filter by:</div>
            <div class='col-md-4'>
                <input type='text' [(ngModel)]='listFilter' />
            </div>
        </div>
        <div class='row' *ngIf='listFilter'>
            <div class='col-md-6'>
                <h3>Filtered by: {{ listFilter }} </h3>
            </div>
        </div>
        <div class='has-error' *ngIf='errorMessage'>{{ errorMessage }}</div>

        <div class='table-responsive'>
            <table class='table' *ngIf='eventlogs && eventlogs.length'>
                <thead>
                    <tr>
                        <th>Event ID</th>
                        <th>Tenant</th>
                        <th>Composition</th>
                        <th>Composition Execution</th>
                        <th>Instrument</th>
                        <th>Start Time</th>
                    </tr>
                </thead>
                <tbody>
                    <tr *ngFor='let eventlog of eventlogs | eventlogFilter:listFilter'>
                        <td> <a [routerLink]="['/eventlog', eventlog.id]">
                            {{ eventlog.id }}
                            </a>
                        </td>
                        <td>{{ eventlog.tenant }} </td>
                        <td>{{ eventlog.composition }} </td>
                        <td>{{ eventlog.compositionExecution }}</td>
                        <td>{{ eventlog.instrument }}</td>
                        <td>{{ eventlog.startTime }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

Component.ts , listFilter is declared Component.ts,listFilter被声明

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

import { IEventlog } from './eventlog';
import { EventlogService } from './eventlog.service';

@Component({
    templateUrl: 'app/eventlogs/eventlog.component.html',
    styleUrls: ['app/eventlogs/eventlog.component.css']
})
export class EventlogComponent implements OnInit {
    pageTitle: string = 'Monitor Event Log';
    listFilter: string = ' ';
    errorMessage: string;
    eventlogs: IEventlog[];

    constructor(private _eventlogService: EventlogService) {

    }

    ngOnInit(): void {
           this._eventlogService.getEventlogs()
                     .subscribe(
                       eventlogs => this.eventlogs = eventlogs,
                       error =>  this.errorMessage = <any>error);
    }

}

For anyone else coming here for the same issue, I started to put all my components in feature modules so I came with the same error, after googling about just found this in the angular official docs : 对于其他任何人来到这里同样的问题,我开始把我的所有组件都放在功能模块中,所以我带来了相同的错误,谷歌搜索后才发现这个角色官方文档

More accurately, NgIf is declared in CommonModule from @angular/common. 更准确地说,NgIf在@ angular / common的CommonModule中声明。

CommonModule contributes many of the common directives that applications need including ngIf and ngFor. CommonModule提供了许多应用程序所需的常用指令,包括ngIf和ngFor。

BrowserModule imports CommonModule and re-exports it. BrowserModule导入CommonModule并重新导出它。 The net effect is that an importer of BrowserModule gets CommonModule directives automatically. 实际效果是BrowserModule的导入器自动获取CommonModule指令。

Just imported that module in my new modules and it was solved. 刚刚在我的新模块中导入了该模块,它就解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2 RC 5 - 无法绑定到&#39;...&#39;,因为它不是&#39;...&#39;的已知属性 - Angular 2 RC 5 - Can't bind to '…' since it isn't a known property of '…' 无法绑定到 &#39;dtOptions&#39;,因为它不是 &#39;table&#39; 的已知属性。 - Can't bind to 'dtOptions' since it isn't a known property of 'table'. 在 Angular 中使用 cdkDropListData 时出错,无法绑定到“cdkDropListData”,因为它不是“div”的已知属性 - Error when using cdkDropListData in Angular gives me Can't bind to 'cdkDropListData' since it isn't a known property of 'div' Angular 2 - 无法绑定到&#39;ngModel&#39;,因为它不是&#39;input&#39;的已知属性 - Angular 2 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“ ngModule”,因为它不是“ input”的已知属性。 在angular 2 asp.net核心中 - Can't bind to 'ngModule' since it isn't a known property of 'input'. in angular 2 asp.net core 离子图标和“无法绑定到&#39;名称&#39;,因为它不是已知的本机属性”错误 - ionic icon and “Can't bind to 'name' since it isn't a known native property” error |官方指南坏了吗?| 无法绑定到“ ngFor”,因为它不是已知的本机属性 - |Official guide broken?| Can't bind to 'ngFor' since it isn't a known native property 错误:模板解析错误:无法绑定到“选项”,因为它不是“图表”的已知属性 - Error: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart' 无法绑定到“数据链接”,因为它不是“td”的已知属性 - Can't bind to 'data-link' since it isn't a known property of 'td' 无法绑定到“ngFor”,因为它不是...在混合 AngularJS 和 Angular 应用程序上的已知属性 - Can't bind to 'ngFor' since it isn't a known property of ... on hybrid AngularJS & Angular application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM