Make sure to always include the keyword private
when declaring your dependencies in the constructor of your DBService
. This automatically adds it as a class member, eliminating the need for redundant assignments like this.dbservice = dbservice
.
constructor(private viewCtrl: ViewController,
private nav: NavController,
private dbservice: DBService) {
this.priority = "high";
}
Don't forget to also add DBService
to the providers array either in your bootstrap call:
bootstrap(App, [/* ..., */ DBService]);
or within your root component (App?):
@Component({
providers: [/* ..., */ DBService],
templateUrl: ...
})
export class App {
In your DBServive, be sure to move the Storage
variable outside of the constructor function to prevent Angular from attempting DI resolution:
@Injectable()
export class DBService {
private storage: Storage;
constructor() {
storage = new Storage(SqlStorage);
...