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

Fastify Typescript: dealing with an unidentified body

I'm new to Fastify and I've encountered a problem with accessing values in the body using Typescript. Does anyone have any ideas or suggestions? Thanks! Update: I want to simplify my code and avoid using app.get(...) Here's my code snippet ...

How can I store unique and only selected checkbox values in an array using Angular?

I need assistance with creating an array from three checkboxes. The array should only contain the values of the checked checkboxes and should not include duplicates. I have attempted to achieve this functionality, but the values are still being added rega ...

Tips for creating cascading dynamic attributes within Typescript?

I'm in the process of converting a JavaScript project to TypeScript and encountering difficulties with a certain section of my code that TypeScript is flagging as an issue. Within TypeScript, I aim to gather data in a dynamic object named licensesSta ...

Extract the JSON array data from the Service and process it within the Component

When passing a response from the Service to the Component for display on the UI, each value needs to be parsed and stored in a variable. This can be achieved by extracting values such as profileId, profileName, regionName, etc. from the response. [{"profi ...

Send an API request using an Angular interceptor before making another call

Within my application, there are multiple forms that generate JSON objects with varying structures, including nested objects and arrays at different levels. These forms also support file uploads, storing URLs for downloading, names, and other information w ...

Tips for sending parameters in Next.js without server-side rendering

I followed the documentation and tried to pass params as instructed here: https://nextjs.org/docs/routing/dynamic-routes However, I encountered a strange issue where the received params are not in string format. How is it possible for them to be in an arr ...

Unable to execute segue for exiting

In my iOS app, there is a transition to a view controller responsible for user authentication. Once the user is signed in, I want to return to the previous view controller. According to a helpful guide I found here, I set up a segue from the authentication ...

The rendering process in ag-grid is resulting in the service component initialized from an event to become null

Currently, I am utilizing ag-grid and need help understanding a specific issue. In my method for preparing GridOptions, I have set up an onCellValueChanged event that triggers a service component to access the database and populate the data. However, when ...

Tips on updating x-label formatting (to display months in words) utilizing morris.js with Angular 5

Snapshot of my Request. I'm looking to alter the xLabel (2018-01 - to - Jan) and I am utilizing morris.js. ...

Send a file to Cloudinary through a stream with the help of PhoneGap

I am currently working on a mobile app project using phonegap. The main functionality of the app is to allow users to capture images with the device's camera and then upload them directly to cloudinary. When a user takes a photo, I can retrieve eithe ...

What is the way to retrieve an array property in a typescript interface?

Imagine a scenario with three interfaces structured as follows: registration-pivot.ts export interface RegistrationPivot { THead: RegistrationPivotRow; TBody: RegistrationPivotRow[]; } registration-pivot-row.ts export interface RegistrationPivotR ...

Set the array as the object attribute

Transitioning my app from AngularJs to Angular 4 has been quite a challenge. I've noticed that the type of statements I frequently used in my code are now failing in Angular 4 (TypeScript): Update: The following lines were previously used in Angular ...

Evolution of ReactJS state over time

When working with React, I wanted to increment a state variable called progressValue by 0.1 every 500 ms until it reaches 100. Here's what I initially tried: const [progressValue, setProgressValue] = React.useState<number>(0) const tick ...

Using Typescript: Utilizing only specific fields of an object while preserving the original object

I have a straightforward function that works with an array of objects. The function specifically targets the status field and disregards all other fields within the objects. export const filterActiveAccounts = ({ accounts, }: { accounts: Array<{ sta ...

Incorrectly selecting an overload in a Typescript partial interface can lead to errors

My attempt to define an overload for my function using a Partial interface overloading is causing typescript to select the incorrect overload interface Args { _id: string; name: string; } interface Result { _id: string; name: string; } function my ...

What is the error message "Cannot assign type 'IArguments' to argument"?

Currently employing a workaround that is unfortunately necessary. I have to suppress specific console errors that are essentially harmless. export const removeConsoleErrors = () => { const cloneConsoleError = console.error; const suppressedWarnings ...

Adding custom type definitions for an untyped npm module in TypeScript 2

Despite attempting various methods recommended in other sources, I am struggling to configure a TypeScript project that utilizes an untyped NPM module. Below is a simplified example along with the steps I have taken. Let's imagine, for this demonstra ...

React with Typescript - Type discrepancies found in Third Party Library

Recently, I encountered a scenario where I had a third-party library exporting a React Component in a certain way: // Code from the third party library that I cannot alter export default class MyIcon extends React.Component { ... }; MyIcon.propTypes = { ...

What is the best way to grab the initial section of a website's text while using a WKWebView?

When working with a WKWebView, retrieving the webpage's title is simple using webView.title. However, obtaining the first paragraph of the webpage's content poses a challenge with no straightforward solution. Any tips or suggestions on how to ac ...

What are the solutions for handling undefined data within the scope of Typescript?

I am encountering an issue with my ngOnInit() method. The method fills a data list at the beginning and contains two different logic branches depending on whether there is a query param present (navigating back to the page) or it's the first opening o ...