任何人都知道如何使用Ionic2 v2.1.0创建angular2服务?Ionic V2 - 创建服务
已经尝试了很多东西,但不断收到错误。
我跟着从这里How to use angular 2 service with Ionic 2一些答案,但它不工作...
这里是我的代码
DataBaseService.ts
import {Injectable} from "@angular/core";
@Injectable()
export class DataBaseService {
constructor() {
}
execSQL() {
console.log('call works');
}
}
进口的“app.component.ts “
import { DataBaseService } from 'DataBaseService';
并把它放在”app.compone nt.ts”
@Component({
templateUrl: 'app.html',
providers: [DataBaseService]
})
如果我运行的应用程序就这样,我得到以下错误
Uncaught Error: Cannot find module "DataBaseService"
DatabaseService的路径是否正确? – MorKadosh
你确定的路径? –
是的! DataBaseService.ts位于app.component.ts的相同路径中! –