0

「準備好」我總是收到此錯誤: 類型錯誤:無法讀取屬性未定義離子:類型錯誤:無法讀取屬性未定義

「準備好」這是我的代碼:

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))"); 
    }); 
}]) 

我也實在沒有想法,爲什麼它似乎無法找到$ ionicPlatform ...

最好的問候, 皮爾遜

回答

1

我想你應該申報這樣

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 

    }) 

服務您的服務功能都可以有自己的依賴。就像在控制器中聲明依賴關係一樣,您可以通過在服務的工廠函數簽名中指定它們來聲明依賴關係。

來源:https://docs.angularjs.org/guide/services

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

+0

THX!第二個版本正在工作。 – Pearson

相關問題