当前位置: 动力学知识库 > 问答 > 编程问答 >

angular2 - Angular 2 unable to import Service from different directory

问题描述:

app

|-ComponentA

|-ComponentB

|-Service

I have made directories for each Component and separate directory for all the services...

when i tried to import service into component A as well as for B

import {ClickedRowItemService} from 'app/Service/customerrowclick.service';

the compiler was unable to detect module and after searching on SO I found this answer:

Add this in tsconfig

{

"compilerOptions": {

"baseUrl": ".",

"paths": {

"*": [

"app/*",

"node_modules/*"

]

}

}

}

and then changing import statement as below solved the compiler error and compiler was able to detect module:

import {ClickedRowItemService} from 'Service/customerrowclick.service';

but when running on browser console-inspect Im getting the error again as:

GET http://localhost:3000/Service/customerrowclick.service 404 (Not Found)

trying to fix the same from yesterday... Pls help!!!

网友答案:

Try relative path from your component.ts like this:

import {ClickedRowItemService} from '../Service/customerrowclick.service'; 

and see if it works.

分享给朋友:
您可能感兴趣的文章:
随机阅读: