Typescript 没有存储提供商!(DBService->;存储)在ionic2中
这是我的应用程序。ts 这是我的服务。ts 我没有得到存储提供商!(DBService->Storage)错误。我相信我的服务有问题, 1) 是我的构造函数没有参数吗? 2) 我不能在getTasks()函数中使用this.storage,甚至不能在构造函数中使用this.storage,为什么 请帮助我,因为我已经困了一天了 使用Typescript 没有存储提供商!(DBService->;存储)在ionic2中,typescript,angular,ionic2,Typescript,Angular,Ionic2,这是我的应用程序。ts 这是我的服务。ts 我没有得到存储提供商!(DBService->Storage)错误。我相信我的服务有问题, 1) 是我的构造函数没有参数吗? 2) 我不能在getTasks()函数中使用this.storage,甚至不能在构造函数中使用this.storage,为什么 请帮助我,因为我已经困了一天了 使用此 看起来service.ts中的函数无法访问构造函数中设置的存储变量 不要使用而是让构造函数中的存储尝试这个。存储如下: constructor() {
此
看起来service.ts中的函数无法访问构造函数中设置的存储
变量
不要使用而是让构造函数中的存储
尝试这个。存储
如下:
constructor() {
this.storage = new Storage(SqlStorage);
}
// home.ts
import { Page } from 'ionic-angular/index';
import { DBService } from './service.ts';
@Page({
templateUrl:"home.html",
providers: [DBService]
})
然后可以从同一类中的任何函数访问它,如下所示
setColor(newColor) {
this.storage.set('color', newColor);
}
储存方法
另外,从中我没有看到查询
方法,但是有一个and选项应该很有用
添加提供者
使用Ionic 2/Angular 2,需要在组件的部分中设置服务。如果您希望服务可用于整个应用程序,则可以在您的全局app.component上提供,也可以仅使其可用于单个组件
在Plunker示例中,我在home组件中设置了它,其中显示providers:[DBService]
,如下所示:
constructor() {
this.storage = new Storage(SqlStorage);
}
// home.ts
import { Page } from 'ionic-angular/index';
import { DBService } from './service.ts';
@Page({
templateUrl:"home.html",
providers: [DBService]
})
感谢您抽出时间来设置工作示例!1) 这是一个实现存储方法的构造函数(publicdbservice:dbService){}inservice.ts2),它得到了查询方法。感谢Adriancariger愿意帮我一把。很酷,很高兴它能帮上忙,也感谢关于
查询
方法的链接!