我需要帮助使我的模块接受我新生成的页面。在我的终端中,我使用离子命令ionic generate page
在我的文件树中创建了两个新页面。一种是隐私政策,另一种是使用条款。它把新的页面建得很好:
**私隐政策网页**
/*
Generated class for the PrivacyPolicy page.
Ionic pages and navigation.
*/
@Component({
selector: 'page-privacy-policy',
templateUrl: 'privacy-policy.html'
})
export class PrivacyPolicyPage {
constructor(public navCtrl: NavController) {}
ionViewDidLoad() {
console.log('Hello PrivacyPolicyPage Page');
}
}
使用条款页
/*
Generated class for the TermsOfUse page.
*/
@Component({
selector: 'page-terms-of-use',
templateUrl: 'terms-of-use.html'
})
export class TermsOfUsePage {
constructor(public navCtrl: NavController) {}
ionViewDidLoad() {
console.log('Hello TermsOfUsePage Page');
}
}
但是当我把页面推到另一个页面上的导航控制器时。我首先在终端中得到了构建错误,上面写着cannot determine module for component PrivacyPolicyPage
(分别是使用页面的术语),然后当我将页面添加到app.module.ts
中的模块时。我发现一个错误,上面写的是unexpected value PrivacyPolicyPage declared by the module AppModule
。
我在这里该怎么做?这是整个app.module.ts文件:
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
//other imports
import { TermsOfUsePage } from '../terms-of-use/terms-of-use';
import { PrivacyPolicyPage } from '../privacy-policy/privacy-policy';
@NgModule({
declarations: [
*otherPages*,
*otherPages*,
TermsOfUsePage,
PrivacyPolicyPage
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
*otherPages*,
*otherPages*,
TermsOfUsePage,
PrivacyPolicyPage
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}
发布于 2017-09-27 17:10:40
ionic generate page <page_name>
命令将为app\pages下的新目录中新创建的页面生成HTML、TypeScript和SCSS文件。
要正确处理AppModule
中的这些组件,导入必须如下所示:
import { TermsOfUsePage } from '../pages/terms-of-use/terms-of-use';
import { PrivacyPolicyPage } from '../pages/privacy-policy/privacy-policy';
// rest of your code
发布于 2017-09-27 11:23:59
你的结构看起来很好!我假设您正在使用来自离子模板的制表符种子项目。如果是,请确保使用NavController推送和pop方法更改视图。
import {PrivacyPolicyPage } from "../privacy-policy/privacy-policy";
// Import statement for the PrivacyPolicyPage
constructor(public navCtrl: NavController, public loadingCtrl: LoadingController) {
//this.presentLoading()
}
// Method to load the privacy policy page
loadPrivacyPolicyPage() {
// import PrivacyPolicyPage in the component
this.navCtrl.push(PrivacyPolicyPage );
}
使用以下命令将CLI更新为最新版本。我使用的是CLI 3.12.0版本
npm install -g ionic@latest
如果有用的话请告诉我。
https://stackoverflow.com/questions/46272260
复制相似问题