创建组件components后,ngFor遍历数据报错
来源:11-10 问题详情页面的数据加载(三)
![](http://img1.sycdn.imooc.com/user/53df9a800001b15201000100-100-100.jpg)
若强
2018-03-23
出错结果:
compiler.es5.js:1694 Uncaught Error: Template parse errors:
Can't bind to 'ngForOf' since it isn't a known property of 'div'. ("
<ul class="keyboard-list">
<li class="list-item clearfix">
<div class="p-item" [ERROR ->]*ngFor="let item of provinceRow1"></div>
<ion-item></ion-item>
</li>
"): ng:///ComponentsModule/SelectCarNoComponent.html@6:30
Property binding ngForOf 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 "@NgModule.declarations". ("
<ul class="keyboard-list">
<li class="list-item clearfix">
[ERROR ->]<div class="p-item" *ngFor="let item of provinceRow1"></div>
<ion-item></ion-item>
</"): ng:///ComponentsModule/SelectCarNoComponent.html@6:10
'ion-item' is not a known element:
1. If 'ion-item' is an Angular component, then verify that it is part of this module
app.module.ts 也导入了ComponentsModule
import { ComponentsModule } from '../components/components.module';
imports:[
ComponentsModule
]
package.json文件
"@angular/common": "^4.4.3",
"@angular/compiler": "^4.4.3",
"@angular/compiler-cli": "^4.4.3",
"@angular/core": "^4.4.3",
"@angular/forms": "^4.4.3",
"@angular/http": "^4.4.3",
"@angular/platform-browser": "^4.4.3",
"@angular/platform-browser-dynamic": "^4.4.3",
"@ionic-native/app-version": "^4.4.2",
"@ionic-native/camera": "^4.3.2",
"@ionic-native/core": "^3.6.0",
"@ionic-native/file": "^4.3.2",
"@ionic-native/file-path": "^4.3.2",
"@ionic-native/qr-scanner": "^4.4.2",
"@ionic-native/splash-screen": "^4.3.0",
"@ionic-native/status-bar": "^4.3.0",
"@ionic-native/transfer": "^3.14.0",
"@ionic/storage": "^2.0.1",
"cordova-android": "^6.2.3",
"cordova-browser": "^4.1.0",
"cordova-ios": "^4.5.1",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-file": "^4.3.3",
"cordova-plugin-file-transfer": "^1.6.3",
"cordova-plugin-filepath": "^1.1.0",
"cordova-plugin-ionic-webview": "^1.1.11",
"cordova-plugin-qrscanner": "^2.5.0",
"cordova-plugin-splashscreen": "~4.0.1",
"cordova-plugin-statusbar": "2.4.2-dev",
"cordova-plugin-swift-support": "^3.1.1",
"cordova-plugin-whitelist": "^1.3.1",
"cordova-sqlite-storage": "^2.0.4",
"ionic-angular": "^3.7.1",
"ionic-plugin-keyboard": "~2.2.1",
"ionicons": "^3.0.0",
"moment": "^2.19.2",
"rxjs": "^5.4.3",
"sw-toolbox": "^3.6.0",
"zone.js": "^0.8.18"
网的上解决方案也不行
https://stackoverflow.com/questions/40331549/cant-bind-to-ngforof-since-it-isnt-a-known-property-of-tr-final-releasehttps://stackoverflow.com/questions/40331549/cant-bind-to-ngforof-since-it-isnt-a-known-property-of-tr-final-release
1回答
-
若强
提问者
2018-03-23
老师我找到问题了,是使用命令行创建组件后,没有自动在components.module.ts文件里面自动导入代码导致
我的默认imports: [],手动加上IonicPageModule就可以了
import { IonicPageModule } from 'ionic-angular';
imports: [IonicPageModule],
112018-03-24
相似问题