gpt4 book ai didi

angular - *ngFor 不适用于 Angular 2

转载 作者:太空狗 更新时间:2023-10-29 17:32:36 24 4
gpt4 key购买 nike

app.module.ts

import { NgModule }       from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { routing } from './app.routing';
import { HttpModule, JsonpModule } from '@angular/http';
import { LoginComponent } from './auth/login.component';
import { SignupComponent } from './register/signup.component';

import { HomeComponent } from './home/home.component';
import { SpinnerComponent} from './uiComponents/page-spinner/Spinner-Component';
import { SpinnerService} from './uiComponents/page-spinner/spinner-service';
import { authProviders } from './auth/auth.providers';
import { LocalStorageService} from './state/local-storage.service';
import {CommonModule} from '@angular/common'

@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,JsonpModule,CommonModule,
routing
// CrisisModule
],
declarations: [
AppComponent,
LoginComponent,
HomeComponent,
SpinnerComponent,
SignupComponent

],
providers: [
authProviders,
SpinnerService,
LocalStorageService
],
bootstrap: [ AppComponent ]
})
export class AppModule {


}

loads.module.ts

import {NgModule} from '@angular/core';

import {LoadsRoutingModule} from './loads.routing';
import {LoadsService} from './services/loads.service';

import {
LoadtypelistComponent,
LoadsComponent,
AnimalsComponent,
BoatComponent,
BulkComponent,
CarComponent,
ContainerComponent,
EquipmentComponent,
FurnitureComponent,
MovingHouseComponent,
OthersComponent,
PalletizedComponent,
ParcelsComponent,
LoadsShared1Component,
LoadsShared2Component
} from './components/index';

@NgModule({
imports: [
LoadsRoutingModule
],
declarations: [
LoadtypelistComponent,
LoadsComponent,
AnimalsComponent,
BoatComponent,
BulkComponent,
CarComponent,
ContainerComponent,
EquipmentComponent,
FurnitureComponent,
MovingHouseComponent,
OthersComponent,
PalletizedComponent,
ParcelsComponent,
LoadsShared1Component,
LoadsShared2Component
],
providers: [LoadsService]
})
export class LoadsModule {

}

组件

import {Component, AfterViewInit,OnInit} from '@angular/core';
import {LoadsService} from '../services/loads.service';
import {VehicleClass} from '../models/file1'

@Component({
selector: 'loads-parcels',
templateUrl: 'Loads/_LoadParcels'
})
export class ParcelsComponent implements OnInit {
classes;
errorMessage:any;

cc=['one','two','three']
constructor(private loadsService: LoadsService) {}
ngOnInit(){
// this.loadsService.getVehicleclasses().then(classes => {this.classes = classes;},error => this.errorMessage = <any>error);
}


}

组件模板

 <div *ngFor="let c of cc">{{c}}
</div>

我收到以下错误:ngFor error

EXCEPTION: Uncaught (in promise): Error: Template parse errors: Can't bind to 'ngForOf' since it isn't a known property of 'div'

有什么帮助吗?

最佳答案

您可能创建了另一个模块并声明了您在那里使用的组件,但是您忘记导入 CommonModule,它提供了通用指令,例如 *ngIf*ngFor 。您不需要在 AppModule 中执行此操作,因为您在其中导入 BrowserModule 并导出 CommonModule,因此这些指令在 中可用应用模块

关于angular - *ngFor 不适用于 Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40037493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com