Encountering issues with creating an instance of imported services in Ionic 2

https://i.sstatic.net/4Fi7V.jpg

https://i.sstatic.net/oisuG.jpg

After creating a service, I tried to use it within an Ionic modal. However, when attempting to instantiate the service, I encountered the error highlighted in the second image. Can anyone provide some insight on how to resolve this issue? Thank you!

Answer №1

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);
        ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble centering an icon in a cell within AG Grid?

I am struggling with aligning my checkmarks within the cells of my AG Grid. Currently, they are all left aligned but I need them to be centered. Adjusting the alignment for text is not an issue, but I can't seem to center the material icons. It appear ...

The module '@angular/cdk/testing' cannot be located

Currently, I am experimenting with the createKeyboardEvent function provided by @angular/cdk/testing to simulate keyboard events: const ENTER_EVENT = createKeyboardEvent('keydown', ENTER, inputNativeElement); Despite installing @angular/cdk usi ...

Changing the color of an input field in Angular Material to red

Below is an example of Angular code where the mat-form will turn red automatically if no value is entered. <mat-form-field> <input matInput placeholder="Enter your email" [formControl]="email" required> </mat-form-field> In the scenar ...

How can I arrange large integers presented with commas (e.g. 54,45,444) in a column using mat sort?

I am having difficulty sorting the column in my Mat Table using mat sort. The numbers being displayed are coming from an API and are formatted with commas at hundreds, thousands, and other places. HTML <ng-container matColumnDef="amount"> ...

The Angular Universal client side appears to be inactive

My server-side rendered application is up and running, but I'm encountering an issue where the client-side functionality seems to be missing. Despite the routes rendering properly, none of the click events or console logs are working on the client sid ...

Tips for creating a webfont using SVG icons

Seeking advice on generating a webfont from SVG icons using webpack, angular2, and typescript. Any suggestions on the best way to achieve this? Struggling to find helpful information online. Please lend a hand! https://i.sstatic.net/kvClK.png The code pr ...

Unable to establish a connection with the server data in pusher.js

I have been trying to set up a collaborative drawing application by following this tutorial. Although I have managed to run the application, the collaborative drawing feature is not working as expected. I have correctly configured the PUSHER_APP_ID, PUSHER ...

Tips for recursively updating a value with javascript functions

Given an array object listarray and passing updatevalue as a parameter, Note: The first larger value will be the first greater value than updatevalue Update the value of updatevalue to the first larger value, then increment the second larger value by add ...

Using TypeScript with Vue allows you to customize the default export of Vue

Currently experimenting with Vue and TypeScript, attempting to compile to AMD in my tsconfig file. The type definition in vue/types/index.d.ts for Vue.js includes: export default Vue; However, this results in TypeScript compiling it like this: import V ...

Issue with sending functions to other components in Angular

I'm currently facing an issue with passing functions to other objects in Angular. Specifically, I've developed a function generateTile(coords) that fills a tile to be used by leaflet. This function is located within a method in the MapComponent. ...

Angular - Async function does not resolve a rejected promise

Currently, my component utilizes an async method for handling file uploads. Here is an example: //component uploadPhotos = async (event: Event) => { const upload = await this.uploadService.uploadPhotos(event, this.files, this.urls); } The UploadSe ...

Angular 4 - Error: Unable to call this.changeHook as it is not a function

![image or error ]1Encountering a strange issue in my Angular 4 application. When I type in input text boxes, an error message TypeError: this.changeHook is not a function appears in the console. I'm struggling to understand the cause of this error. A ...

A guide on incorporating ngFor with the flipping card feature in Angular

I am attempting to use ngfor to create some flip cards. However, the cards are not starting a new line and are overlapping in the first line. I have a total of 4 cards, but the 4th card is overlapping with the 1st card. I believe this issue is related to t ...

Why do my messages from BehaviorSubject get duplicated every time a new message is received?

Currently, I am using BehaviorSubject to receive data and also utilizing websockets, although the websocket functionality is not relevant at this moment. The main issue I am facing is why I keep receiving duplicated messages from BehaviorSubject. When exa ...

Encountering TypeScript Error in Fresh VueJs3 Installation - Deprecated Option 'importsNotUsedAsValues'

{ "extends": "@vue/tsconfig/tsconfig.web.json", "include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "exclude": ["src/**/__tests__/*"], "compilerOptions": { ...

Having trouble initiating an application using a component other than the AppComponent

In my Angular project, I am trying to initiate the Application with FleshScreenComponent instead of AppComponent. Even after replacing appComponent with FleshScreenComponent in the bootstrap of module.ts file, I am encountering an error: The selector " ...

In Typescript, default parameters can be inferred during type inference

Illustrative example of the concept I am attempting to implement: const simpleExample = <T>(v: T = 'cat') => { return v; }; Issue encountered: Error message: Type 'string' is not assignable to type 'T'. 'T&a ...

Incorporating a JSX Component within a TSX Component results in a compilation error

Recently, I encountered an issue with my typescript-react component named ContractExpenses. The problem arose when I tried to integrate a JSX component called DynamicSelector within it, resulting in the following error: https://i.sstatic.net/BMMir.png Be ...

Tips for addressing the ESLint issue stating that the package should be included in dependencies instead of devDependencies

Struggling to properly lint my React+Typescript project with ESLint. In one of my components, I'm utilizing the useParams hook from react-router. import { useParams } from 'react-router'; However, ESLint is throwing an error on that line: E ...

Angular routing typically directs users to the home page

I've been struggling for hours trying to solve what seems like a simple issue. I have a route called page2 set up in the following way: // app.module.ts import { Page2Component } from './page2/page2.component'; @NgModule({ declarations: ...