无法绑定到"ngforOf",因为它不是已知的本机属性 [英] Can't bind to 'ngforOf' since it isn't a known native property

查看:193
本文介绍了无法绑定到"ngforOf",因为它不是已知的本机属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于它不是已知的本机属性,因此无法绑定到"ngforOf"

Can't bind to 'ngforOf' since it isn't a known native property

    <h4>Colors bad boys</h4>
    <ul><li [ERROR ->]*ngfor="#color of colors">
        <span>{{color.color | upperCase}}</span>
      </li>

尝试通过TemplateParser或RuntimeMetadataResolver加载模板 并在angular2 bootstrap中注入overwtitten方法,例如用于RuntimeMetadataResolver

Trying to load the template via TemplateParser or RuntimeMetadataResolver and inject the overwtitten method in angular2 bootstrap e.g. for RuntimeMetadataResolver

模板正确加载了其内容,但解析失败并显示错误

The template loads its content correctly, but parsing fails with the error

由于它不是已知的本机属性,因此无法绑定到"ngforOf"

Can't bind to 'ngforOf' since it isn't a known native property

推荐答案

请注意大小写,*ngFor(大写F),而不是*ngforng-for

Pay attention to the casing, it is *ngFor (capital F), not *ngfor or ng-for.

要修正您的示例,请使用:

To fix your example, use:

...
<ul><li *ngFor="#color of colors">
...

请再次注意,它是*ngFor,而不是*ngfor.

Notice, again, it is *ngFor, not *ngfor.

显示问题和更正的两个问题:

Two plunkers showing the problem and correction:

这是一个与您有相同错误的插件(请查看app/app. component.ts和控制台):

Here's a plunker with that same error you have (look at app/app.component.ts and the console):

由于它不是已知的本机属性,因此无法绑定到"ngforOf"

Can't bind to 'ngforOf' since it isn't a known native property

然后在这另一台插销器中,完全相同的代码已修复*ngForF).

And then the exact same code, fixed, in this other plunker (just changed the F of *ngFor).

在Angular的最新版本中,我们有 @NgModule 需要一些其他配置.

In recent versions of Angular we have @NgModules which require some additional configuration.

要获取*ngFor,请在您的 app模块中导入

To get *ngFor, in your app module you have to import BrowserModule:

import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  imports:      [ BrowserModule ],
  // ...
})
export class AppModule { }

其他模块 ,导入 CommonModule :

import { CommonModule } from '@angular/common';

@NgModule({
  imports:      [ CommonModule ],
  // ...
})
export class OtherModule { }

这篇关于无法绑定到"ngforOf",因为它不是已知的本机属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆