Ionic: Error - Unable to access the 'ready' property of an undefined object

I keep encountering this error message: TypeError: Cannot read property 'ready' of undefined

Here is the snippet of my code:

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.directives','app.services', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
});
});

angular.module('app.services', [])
.service('DatabaseService', [function($cordovaSQLite, $ionicPlatform) {
    var db;

    $ionicPlatform.ready(function () {
    if(window.cordova) {
        db = $cordovaSQLite.openDB("auftragDB");    
    } else {
        db = window.openDatabase("auftragDB", "1.0", "Offline Artikel Datenbank", 10*1024*1024);
    }

    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS ArtikelTable (ticket_id number(10), kunde char(100))");
     });
}])

I am really puzzled as to why it can't seem to locate the $ionicPlatform...

Warm regards, Pearson

Answer №1

If you're looking to define your service function, consider structuring it like this:

angular.module('app.services', [])
.service('DatabaseService', ['$cordovaSQLite', '$ionicPlatform', function($cordovaSQLite, $ionicPlatform) {

 // When using the second argument of .service() as an array,
 // make sure to list all dependencies followed by the function that utilizes them

}])

Alternatively, you can use this format:

angular.module('app.services', [])
    .service('DatabaseService', function($cordovaSQLite, $ionicPlatform) {

     // Another option is to directly use a function with dependencies as parameters.
     // Be cautious when minifying code, as dependency injection could be affected.

    })

Like controllers, services can have their own dependencies. These dependencies are specified within the service's factory function signature.

Source: https://docs.angularjs.org/guide/services

More: https://docs.angularjs.org/guide/di

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

JSON failing to show all values sent as a string

In a div element there is a table with 3 rows, a textarea, and a button. The JSON data populates the first 3 rows correctly but the textarea remains blank. My goal is to display the previous record from the database in the textarea. function ChangeLoadin ...

How does the 'order' stack up against the 'products' array? Display the names of the products that are included in the order

I have an array of items for sale: const products = { { id: product1, name: 'Product A', price: 100 }, { id: product2, name: 'Product B', price: 200 }, { id: ...

The Angular 2 rollup AoT compilation results in a larger build size compared to the standard JiT build

I'm facing an issue with reducing the weight of my app during the building process. I am using Angular 2 seed as a starting point. https://github.com/mgechev/angular-seed When I run: npm run build.prod my app.js file size is 1.5MB. However, when I ...

Tips for deactivating dates in the jquery datepicker that correspond to entries in a MySQL database

Is there a way to disable dates directly from a MySQL database in jQuery Datepicker? It seems tedious to constantly update dates in JavaScript, so I'm exploring the option of storing future disable dates in the MySQL database and displaying them in th ...

What causes the Error: ENOENT open error to occur when attempting to render a doT.js view?

My first experience with doT.js led me to create a basic server setup: 'use strict'; var express = require('express'); var app = express(); var doT = require('express-dot'); var pub = __dirname+'/public'; var vws ...

What are the various ways to apply unique padding styles to ng-repeat items?

Take a look at this image. I need to position my 6 boxes on the 6 vertical lines above the image. I am struggling with applying different padding styles to my ng-repeat directive. Although I tried using [ng-class], it doesn't seem to work as expected. ...

What is the best method for displaying the date/time with timezone in AngularJS?

While utilizing the AngularJS filter date, I have incorporated the following code snippet: var date = new Date("09 apr 2015 12:00:50 UT"); $filter('date')(date, "dd MMM yyyy hh:mm:ss a Z"); The current output is: 09 Apr 2015 08:19:04 PM + ...

Extract portions of the date into individual variables

My current project involves creating a front-end interface for data stored in a JSON database. The date information is saved in the following format: 12/31/16 I am trying to extract each of these values individually. Is there a method to assign variabl ...

Incorporating a new parameter into the JSON response from SoundCloud

Currently, I am in the process of developing an app utilizing the SoundCloud JavaScript API. My approach involves fetching the JSON data from: http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=YOUR_CLIENT_ID ...

What is the best method for showcasing numerous dropdown lists using JavaScript along with conditional if-else statements?

Hello everyone, I am currently new to javascript and I'm attempting to build a small web application using javascript. However, I am facing an issue with printing the drop-down list output. Could someone please assist me in resolving this problem? < ...

Utilizing Jquery.validate() for personalized checkbox validation

My struggle lies in integrating jQuery.validate() with custom-designed checkboxes. I am unable to achieve the desired outcome where, upon clicking SUBMIT without selecting any checkboxes, an error should be displayed in the respective label. Despite having ...

What is the impact on positioning when including a class in Angular?

I've encountered a peculiar bug while trying to add a class to a ui-router element. When I apply the active class, an absolutely positioned element that spans the entire view suddenly snaps to the width of its parent. To see the issue in action, chec ...

What is the best way to extract JSON data from a remote URL?

Having recently started with JavaScript, I am looking to parse JSON from an external URL using pure JavaScript. Currently, I have the following code: var getJSON = function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, tr ...

Toggle the visibility of an element with a single button click

Below is a snippet of my sample code: SAMPLE HTML CODE: <ul> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <l ...

Having trouble with linking an external JavaScript file inside the head tag?

I've connected my script.js file to my index.html file, and both files are located in the same directory. I initially linked the script.js file in the <head> section, but it wasn't working as expected. Upon checking the console, I encounter ...

Tips for executing npm/grunt commands within Jenkins

Hi everyone, I'm new to this area and currently facing a challenge with setting up Jenkins. I have been attempting to execute the following commands from Jenkins: npm install grunt quickStart As of now, I have Jenkins running on a Windows machine as ...

Showing real-time information from an object

I am attempting to showcase the 'helpText' data on the front end based on the type. Is it feasible to include a conditional statement (metricsType variable) and the [key] value into what I want to return? The final 'p' below provides an ...

Gathering feedback from a webpage using JavaScript and jQuery

I have been experimenting with different tools such as Selenium and BeautifulSoup in an attempt to scrape the contents of the following website/pages: . Specifically, I am looking to extract the reviews/sections which are dynamically loaded by JS, jQuery ...

"Unspecified error in Angular" encountered when implementing Mobile Angular UI in conjunction with Angularfire

I am currently working on developing a mobile app using Mobile Angular UI and integrating it with a Firebase database. However, I keep encountering an error when trying to include Firebase: Uncaught ReferenceError: angular is not defined at angularfire.m ...

How to smoothly transition a div from one location to another using animations in an Ionic3-Angular4 application

I'm attempting to incorporate some animation into my Ionic 3 mobile app. Specifically, I want to shift a div from one location to another. In the code snippet provided below, I am looking to move the div with the "upper" class after the timeline-item ...