Angular 4:NGF用于内部html不工作
这在我的product.component.html中Angular 4:NGF用于内部html不工作,angular,Angular,这在我的product.component.html中 <div class="col-md-6"> <table class="table table-bordered table-responsive"> <thead> <tr> <th class="text-center">Име</th> <th
<div class="col-md-6">
<table class="table table-bordered table-responsive">
<thead>
<tr>
<th class="text-center">Име</th>
<th class="text-center">Фамилия</th>
<th class="text-center">Град</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let i as months">
<td>{{i}}</td>
</tr>
</tbody>
</table>
</div>
导出类ProductComponent{
months = ["January", "Feburary", "March", "April", "May",
"June", "July", "August", "September",
"October", "November", "December"];
}
这在我的app.module.ts中
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {RouterModule} from'@angular/router';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { ItemComponent } from './item/item.component';
@NgModule({
declarations: [
AppComponent,
ProductComponent,
ItemComponent
],
imports: [
BrowserModule,
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我没有使用ngFor以html格式打印我的月份,因为错误“无法绑定到'ngForAs',因为它不是'tr'的已知属性。”(“首先,您的导入中缺少
CommonModule
。请将其添加到AppModule
:
import { CommonModule } from `@angular/common';
imports: [
CommonModule,
BrowserModule,
FormsModule,
],
其次,*ngFor
语法错误。请将其更正为以下内容
<tr *ngFor="let i of months">
我认为应该是
let i of months
而不是let i as months
在你的*NGOK这项工作中,但是在我的html中“*ngFor=“let”是红色下划线不是intellisense。我的IDE Netbeans 8,2
<tr *ngFor="let i of months">