typescript 角度“必须导入或本地”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47124097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:00:51  来源:igfitidea点击:

Angular "Must be imported or local" error

angulartypescriptionic-frameworkionic3

提问by Drew

I am trying to create an ionic application, and when I go to link pages together in the ionic creator, I am getting an error on the .ts file as follows:

我正在尝试创建一个 ionic 应用程序,当我在 ionic creator 中将页面链接在一起时,我在 .ts 文件中收到如下错误:

 typescript: src/pages/home/home.ts, line: 4 
            Individual declarations in merged declaration 'HomePage' must be all exported or all local. 

       L3:  import { NotificationsPage } from '../notifications/notifications';
       L4:  import { HomePage } from '../home/home';
       L5:  import { MyPatientsPage } from '../my-patients/my-patients';

Below is the code from my .ts file:

下面是我的 .ts 文件中的代码:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NotificationsPage } from '../notifications/notifications';
import { HomePage } from '../home/home';
import { MyPatientsPage } from '../my-patients/my-patients';
import { AllPatientsPage } from '../all-patients/all-patients';
import { LoginPage } from '../login/login';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {
  }
  goToNotifications(params){
    if (!params) params = {};
    this.navCtrl.push(NotificationsPage);
  }goToHome(params){
    if (!params) params = {};
    this.navCtrl.push(HomePage);
  }goToMyPatients(params){
    if (!params) params = {};
    this.navCtrl.push(MyPatientsPage);
  }goToAllPatients(params){
    if (!params) params = {};
    this.navCtrl.push(AllPatientsPage);
  }goToLogin(params){
    if (!params) params = {};
    this.navCtrl.push(LoginPage);
  }
}

回答by Sampath

You must not importthe HomePageinside the home.tsfile.i.e.Line 4

你不能importHomePage里面的home.ts文件。IELine 4

Need to remove below import from the home.tsfile

需要从home.ts文件中删除以下导入

import { HomePage } from '../home/home';