简体   繁体   English

Ionic:TypeError:无法读取未定义的属性“ ready”

[英]Ionic: TypeError: Cannot read property 'ready' of undefined

I am always getting this error: TypeError: Cannot read property 'ready' of undefined 我总是收到此错误:TypeError:无法读取未定义的属性“ ready”

This is 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 have really no idea, why it seems to can't find the $ionicPlatform... 我真的不知道,为什么它似乎找不到$ ionicPlatform ...

Best regards, Pearson 最好的问候,皮尔森

I think you should declare your service function like this 我认为您应该这样声明服务功能

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

 // When you pass second argument of .service() as array, 
 // then the array should list all dependencies followed by function which use them 

}])

OR 要么

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

     // or you can use a direct function with all dependencies as its parameter. 
     // But dependencies injection will break if you do code minification

    })

Services can have their own dependencies. 服务可以具有自己的依赖性。 Just like declaring dependencies in a controller, you declare dependencies by specifying them in the service's factory function signature. 就像在控制器中声明依赖项一样,您可以通过在服务的工厂函数签名中指定依赖项来声明依赖项。

Source: https://docs.angularjs.org/guide/services 资料来源: https : //docs.angularjs.org/guide/services

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义IONIC2的属性“就绪” - TypeError: Cannot read property 'ready' of undefined-IONIC2 TypeError:无法读取未定义的属性“就绪” - TypeError: Cannot read property 'ready' of undefined Angularjs / Ionic TypeError:无法读取未定义的属性&#39;then&#39; - Angularjs/Ionic TypeError: Cannot read property 'then' of undefined 未捕获的TypeError:无法读取未定义的Vimeo属性&#39;ready&#39; - Uncaught TypeError: Cannot read property 'ready' of undefined Vimeo 无法读取未定义的属性“就绪”; 区:<root> ; 任务: Promise.then ; 值:类型错误:无法读取未定义的属性“就绪” - Cannot read property 'ready' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'ready' of undefined ionic.bundle.js TypeError:无法读取未定义的属性“ add” - ionic.bundle.js TypeError: Cannot read property 'add' of undefined 错误类型错误:无法读取未定义的属性“toLowerCase”。 离子 3 - ERROR TypeError: Cannot read property 'toLowerCase' of undefined. Ionic 3 JS / Ionic:TypeError:无法读取未定义的属性“代码” - JS/Ionic:TypeError: Cannot read property 'code' of undefined TypeError:无法读取未定义的属性“open”(Phonegap和Ionic) - TypeError: Cannot read property 'open' of undefined (Phonegap and Ionic) 错误类型错误:无法读取未定义 Ionic/Firestore 的属性“用户名” - ERROR TypeError: Cannot read property 'username' of undefined Ionic/Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM