离子4离子角<ion-button>不是已知的元素

时间:2019-02-19 08:19:43

标签: angular ionic-framework components ionic4

我正在对ionic 4进行拍摄。我创建了一个新项目:

ionic start newApp blank --type=ionic-angular

我已经习惯了ionic-angular

在package.json中,我有以下内容:

{
  "name": "courier-app",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/core": "~4.18.0",
    "@ionic-native/splash-screen": "~4.18.0",
    "@ionic-native/status-bar": "~4.18.0",
    "@ionic/storage": "2.2.0",
    "ionic-angular": "^3.9.3",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.29"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.1",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project"
}

您可以清楚地看到ionic-angular的最新版本是3.9:

"ionic-angular": "^3.9.3"

尽管IonicModule已导入app.module.ts,但我将LoginPage设置为首先要加载的根页面:

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    LoginPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    LoginPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

在app.component.ts中:

rootPage:any = LoginPage;

当我在登录页面上添加登录按钮时:

<ion-button (click)="login()">Login</ion-button>

我有一个错误在说:

<ion-button> is not a known element

使用此post的答案,我将其更改为:

<button ion-button ...>Login</button>

但是据我所知,离子4中的组件的行为(无论类型如何)都是使用<ion-button>而不是<button ion-button>

是否存在任何缺失的进口,或者这仅仅是离子4型离子角的新行为?

1 个答案:

答案 0 :(得分:3)

要启动Ionic 4项目,您必须

append --type=angular

到您的 start command

ionic start project1 blank --type=angular

否则,CLI将生成一个Ionic 3项目,因此这些示例将失败。