Error: Reference to an undeclared variable cannot be accessed. TypeScript, Cordova, iOS platforms

Can anyone offer some advice on what might be the issue? I'm encountering an error while building my Ionic app on the IOS platform, but everything is running smoothly on Android.

ReferenceError: Cannot access uninitialized variable.   service.ts:31

On line 31 of the service.ts file, I have a class declaration.

https://i.stack.imgur.com/nHxaM.jpg

Any insights into what I could be doing wrong?

Answer №1

Michelle Carter, please share the entire code snippet.

import {Injectable} from '@angular/core';
import {SqlService} from "./sql.service";
import {Subscriptions} from '../models/subscriptions';

import {Platform/*, Events*/ } from '@ionic/angular';

import {Events} from './events.service';

import {UserServiceService} from './user-service.service';
/*import { BackgroundMode } from 'ionic-native';*/
import {ModelsServiceService} from './models-service.service';
import {User} from '../models/user';

import {UpdateNewProviderService} from "./update-new-provider.service";
import {LogProviderService} from "./log-provider.service";
import { HTTP } from '@ionic-native/http/ngx';
import {LoginProviderService} from "./login-provider.service";

import { Device } from '@ionic-native/device/ngx';


//BackgroundMode.enable();

@Injectable({
  providedIn: 'root'
})

export class SubscriptionsServiceService {

  //storage:Storage = null;
  //products:Array<Object>;

  products:any;
  public count = 0;
  public output;
  public checksubscription: string;

  constructor(
      private sql: SqlService,
      public platform: Platform,
      public updateNewProvider: UpdateNewProviderService,
      public userService: UserServiceService,
      public logProvider: LogProviderService,
      public http: HTTP,
      public events: Events,
      private device: Device,
      public loginProvider: LoginProviderService,
      public modelService: ModelsServiceService
  ) {

    this.products = [];
    // this.storage = new Storage();
    this.platform.ready().then(() => {

      this.checksubscription = this.loginProvider.rootUrl + 'checksubscription.php';


    });

  }

  addSubscription(subsc: Subscriptions){

    console.log("subsc",subsc);

    let save = 'INSERT INTO subscription (user_id, external_id, description, active, url,work_order,bu_url,iu_url,bu_url_local_path,iu_url_local_path,mu_url,mu_url_local_path,sc,server_date,date_warning,date_auth,run_warning_message,run_warning_message_time,update_method,iurl,murl,rurl,ua,status,pi,ms) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';

    console.log(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active, subsc.url]);

    return this.sql.query(save, [subsc.user_id, subsc.external_id, subsc.description, subsc.active,
      subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
      subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
      subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time,subsc.update_method,subsc.iurl,subsc.murl, subsc.rurl, subsc.ua, subsc.status, subsc.pi, subsc.ms]);
  }

  addNewSubscription(subsc: Subscriptions):Promise<any>{
    return new Promise((resolve,reject)=>{

      console.log("addNewSubscription", subsc);

      this.selectCurrentSubscription(subsc).then(d=>{

        if (undefined !== d) {

        if (d.res.rows.length>0)
        {
          let save = 'UPDATE subscription SET description =?, active =?, url =?, work_order=?,bu_url=?,iu_url=?,bu_url_local_path=?,iu_url_local_path=?,mu_url=?,mu_url_local_path=?,sc=?,server_date=?,date_warning=?,date_auth=?,run_warning_message=?,run_warning_message_time=?,update_method=?,iurl=?,murl=?, rurl=?, ua=?, status=?, pi=?, ms=? WHERE user_id=? AND external_id= ?';
          this.sql.query(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
            subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
            subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
            subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time, subsc.update_method,subsc.iurl,subsc.murl, subsc.rurl, subsc.ua, subsc.status, subsc.pi,  subsc.ms]).then(() => {

            //console.log(save ,[subsc.description,subsc.active,subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.user_id, subsc.external_id]);

            resolve(true);
          //}).catch(err =>{reject(err)});
          }).catch(err => {


            console.log("err catch",err);
            reject(err);
          });


        }
        else
        {
          let save = 'INSERT INTO subscription (user_id, external_id, description, active, url,work_order,bu_url,iu_url,bu_url_local_path,iu_url_local_path,mu_url,mu_url_local_path,sc,server_date,date_warning,date_auth,run_warning_message,run_warning_message_time,update_method,iurl,murl,ua,status,pi,ms) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
          this.sql.query(save,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
            subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
            subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
            subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time,subsc.update_method,subsc.iurl,subsc.murl, subsc.ua, subsc.status, subsc.pi, subsc.ms]).then(()=>{


            /*            console.log(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
                                          subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path]);*/

            resolve(true);
          //}).catch(err=>{reject(err)});
          }).catch(err => {

            console.log("err catch",err);
            reject(err);
          });


        }

        }

      });
    });

  }
}

Answer №2

If you can provide the full content of service.ts, that would be helpful as the error may be stemming from a previous line and affecting everything after it.

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

Enable Ace Editor's read-only mode

I'm having some difficulty getting my ace-editor to work in read-only mode. I'm working with Angular 9 and I've attempted the following approach: In my HTML file, I have the following code: <ace-editor mode="java" theme="m ...

Error in Angular: Http Provider Not Found

NPM Version: 8.1.4 Encountered Issue: Error: Uncaught (in promise): Error: Error in ./SignupComponent class SignupComponent_Host - inline template:0:0 caused by: No provider for Http! Error: No provider for Http! The error message usually indicates the a ...

What causes type checks to be skipped when spreads are used on type-guarded types?

Query: Why doesn't a compile-time error occur when I overlook adding nested fields to an object of type T, while constructing the object using object spread? Illustration: interface User { userId: number; profile: { username: string } } f ...

Mastering the process of importing AngularJS submodules in TypeScript

Currently, I am in the process of structuring an AngularJS (Angular 1) project using TypeScript. To compile TypeScript & ES6 to JavaScript, I have set up webpack. In my webpack configuration, I only compile the "app.ts" file and any other files it imports ...

Encountering an issue with Jest when using jest.spyOn() and mockReturnValueOnce causing an error

jest --passWithNoTests --silent --noStackTrace --runInBand --watch -c jest-unit-config.js Project repository An error occurred at jest.spyOn(bcrypt, 'hash').mockRejectedValue(new Error('Async error message')) Error TS2345: The argum ...

An issue occurred while attempting to retrieve Firebase data using an HTTP GET request

When trying to retrieve my data from firestore using an HTTP get request, I encountered an error. It might be helpful if my data in firestore was stored in JSON format. I'm not sure if this is feasible. <!DOCTYPE html> <html lang="en"> ...

The ins and outs of Angular's type checking mechanisms

I have a few different scenarios on my mind. Imagine if I make an http call to fetch all movies from my php backend api. This is observable, so I need to subscribe to it. // Here's my service getAll() : Observable<Movie[]>{ this.http.get ...

Moving from Http to HttpClient in Angular4Changeover your Angular4

I recently migrated my Angular app to use the new HttpClient, but I'm encountering some challenges in achieving the same results as before with Http. Can anyone help me out? Here's what I was doing with Http: getAll() { return this.http.get ...

Choosing the Right Language for AngularJS 2: TypeScript, JavaScript, or Dart?

AngularJS 2 is on the horizon, and the documentation recommends three languages: Typescript, Javascript, and Dart. As someone who primarily works with Javascript EcmaScript 5, I'm curious about the strengths and weaknesses of these three options. Cu ...

Calculating the sum of values in a JSON array using a specific parameter in Typescript

A flat JSON array contains repetitive identifier, categoryId, and category: data: [ { "identifier": "data", "categoryId": "1", "category": "Baked goods", "product": "Aunt Hattie's", "price": "375" } ...

Implementing DeviceEventEmitter in an iOS Environment

I'm currently developing a react-native application. I've encountered an issue where I am able to emit events from native Android code to my react native app successfully, but facing difficulties with iOS. While the events sent from native Andro ...

What is the proper way to bring in Typescript types from the ebay-api third-party library?

My TypeScript code looks like this: import type { CoreItem } from 'ebay-api'; declare interface Props { item: CoreItem; } export default function Item({ item }: Props) { // <snip> } However, I encounter an issue when trying to build ...

The error message "Alamofire JSON POST response failed: Lost connection to the network" was displayed

Many individuals encounter this error for various reasons. I have yet to come across a solution that resolves my specific issue. In order to log my Alamofire requests, I utilize Timberjack. While all of my GET requests function properly and return JSON d ...

Tips for eliminating nested switchMaps with early returns

In my project, I have implemented 3 different endpoints that return upcoming, current, and past events. The requirement is to display only the event that is the farthest in the future without making unnecessary calls to all endpoints at once. To achieve th ...

How can I stop TypeScript from causing my builds to fail in Next.js?

Encountering numerous type errors when executing yarn next build, such as: Type error: Property 'href' does not exist on type '{ name: string; }'. This issue leads to the failure of my build process. Is there a specific command I can ...

Expand the data retrieved from the database in node.js to include additional fields, not just the id

When creating a login using the code provided, only the user's ID is returned. The challenge now is how to retrieve another field from the database. I specifically require the "header" field from the database. Within the onSubmit function of the for ...

Having trouble with errors when adding onClick prop conditionally in React and TypeScript

I need to dynamically add an onClick function to my TypeScript React component conditionally: <div onClick={(!disabled && onClick) ?? undefined}>{children}</div> However, I encounter the following error message: Type 'false | (() ...

Challenges encountered when sending an HTTP post request in Ionic 2 with Angular 2

Whenever I try to make a post request in my ionic2 application, I encounter an error without any specific message. It seems like there is something wrong with my Angular2 post request. Below is the function I am using for the request: load(username, pass ...

"Enhance your PrimeVue Tree component with interactive action buttons placed on every TreeNode

Details: Using Vue 3.3.6 in composition API script setup style Utilizing PrimeVue 3.37.0 and PrimeFlex 3.3.1 Implemented with Typescript Objective: To create a tree structure with checkboxes that are selectable, along with action buttons on each TreeNod ...

Exploring the use of a customizable decorator in Typescript for improved typing

Currently, I am in the process of creating TypeScript typings for a JavaScript library. One specific requirement is to define an optional callable decorator: @model class User {} @model() class User {} @model('User') class User {} I attempted ...