简体   繁体   English

角度2:导入无法找到模块的问题

[英]Angular 2: Problems with imports not finding modules

In our Ionic 2 + Angular 2 project, we had a folder "profile" in which we had "profile.html" and "profile.ts", and in the latter, we had three components which are two modals and a dialog. 在Ionic 2 + Angular 2项目中,我们有一个文件夹“ profile”,其中有“ profile.html”和“ profile.ts”,而在后者中,我们有三个组件,分别是两个模式和一个对话框。

As the file "profile.ts" was so big with these components, I moved two of them (the other was tiny and made sense in that same file), all to specific files in the same folder: "profileEdit.ts", "hobbiesDialog.ts", resulting in this folder tree: 由于文件“ profile.ts”包含这些组件太大,因此我将其中两个(另一个很小,并且在同一个文件中有意义)移动到了同一文件夹中的特定文件:“ profileEdit.ts”,“ hobbiesDialog.ts”,生成以下文件夹树:

$project/src/pages/profile $ project / src / pages / profile

  • profile.ts profile.ts
  • profile.html profile.html
  • profileEdit.ts profileEdit.ts
  • profileEDit.html profileEDit.html
  • profile.scss profile.scss
  • hobbiesDialog.ts (the template is coded inside) hobbiesDialog.ts(模板编码在里面)

So now, my profile.ts has these imports: 所以现在,我的profile.ts具有以下导入:

import { Component, Input } from '@angular/core';
import { NavController, ViewController, PopoverController, ModalController } from 'ionic-angular';
import { AlertController, ToastController, NavParams } from 'ionic-angular';
import  Parse from 'parse';

import { LoginPage } from '../login/login';
import { ProfileEditModal } from 'profileEdit';

The last one is failing: somehow, Angular can't find the module: 最后一个失败:以某种方式,Angular找不到模块:

Uncaught Error: Cannot find module "profileEdit" at eval 未捕获的错误:在eval找不到模块“ profileEdit”

I also added these modules to the app.module.ts: 我还将这些模块添加到app.module.ts中:

// more imports
import { ProfilePage, ProfilePopover } from '../pages/profile/profile';
import { ProfileEditModal } from '../pages/profile/profileEdit';
import { HobbiesPopover } from '../pages/profile/hobbiesDialog';

Also added them in the declarations and entryComponents arrays of @NgModule. 还将它们添加到@NgModule的声明和entryComponents数组中。

... but it won't work! ...但是它行不通! It used to work when it was in a single file, but now it doesn't. 它曾经在单个文件中时可以工作,但现在不行了。 What am I doing wrong here? 我在这里做错了什么?

每当导入同一目录级别的类时,都应该像导入

'./fileName.extension'

尝试import { ProfileEditModal } from './profileEdit';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM