简体   繁体   English

Angular2,找不到模块“ app / models / user”错误

[英]Angular2, cannot find module 'app/models/user' error

I was trying the example on https://sniederm.wordpress.com/2017/04/12/tutorial-ng2-rest-service/ and in step 2, in "user.service.ts" file I am getting " cannot find module 'app/models/user' " error on the 我正在https://sniederm.wordpress.com/2017/04/12/tutorial-ng2-rest-service/上尝试该示例,并且在步骤2中,我正在“ user.service.ts”文件中找到“找不到上的模块“ app / models / user”错误

import { User } from "app/models/user";

line. 线。 I tried couple of things that I can find on web, such as replacing the "app" with "." 我尝试了一些可以在网上找到的方法,例如将“ app”替换为“”。 in "app/models/user" but it did not work. 在“应用程序/模型/用户”中,但是它不起作用。

In the tutorial it says " we will create a class User and place it in a file called user.ts within the „to-be-created“ subfolder app/models. " I am new to angular so at first I created this folder manually (right click->new folder) but then after I get the error, I created models folder with ng generate module models prompt. 在本教程中,它说:“ 我们将创建一个User类,并将其放在“要创建的”子文件夹app / models中的一个名为user.ts的文件中。 ”我是angular的新手,因此首先我手动创建了此文件夹(右键单击->新文件夹),但是在收到错误消息后,我用ng generate module models提示创建了models文件夹。 But still I get the error. 但是我仍然得到错误。 The user.ts file is in models folder. user.ts文件在models文件夹中。 Can somebody help me with this, please? 有人可以帮我吗?

Assuming that your files structure is as below: 假设您的文件结构如下:

|app
 |models
  |user.ts
 |services
  |user.service.ts

Your import should be: 您的导入应为:

import { User } from "../models/user";

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

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