Ionic サービスについて質問があります。ご存知のように、Ionic フレームワークには、services.js ファイルを含む js ディレクトリを含む www ディレクトリが組み込まれています。私の最初のサービスは機能します。同じservices.jsファイルに別のサービスを書き込もうとしたところ、エラーが発生しました: Uncaught "SyntaxError: Unexpected token . http://localhost:8100/js/services.js「(index):28 Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: Error: [$injector:modulerr] Failed to instantiate module starter.services due to: エラー: [$injector:nomod] モジュール 'starter.services' は利用できません! モジュール名のつづりを間違えたか、モジュールをロードするのを忘れました。モジュールを登録する場合は、必ず依存関係を 2 番目の引数として指定してください。
//services.js
//the first factory, API works
angular.module('starter.services', [])
.factory('API', function($http) {
var apiFooUrl = 'http://localhost:3000/api/do/thing'
return {
all: function(){
return $http.get(apiFooUrl + 's')
},
show: function(thingID){
console.log("stock service get running", thingID);
return $http.get(apiFooUrl + '/' + thingID)
}
};
});
//this is the one that returns the error
.factory('Users', function($http) {
var apiUrl = 'http://localhost:3000/api/users/'
return {
index: function(){
return $http.get(apiUrl)
}
show: function(id){
return $http.get(apiUrl + id)
}
}
})
詳細情報のために編集:David Lのコメントに応じて: GlobalCtrl に次のように挿入しました:
.controller('GlobalCtrl', function(Users, $rootScope, $state, $window,
Things, $scope){
$scope.newUser = {}
$scope.user = {}
//show all Users
Users.index().success(function(results){
$scope.users = results
})
})
DetailCtrl にも挿入されます。app.js では、サービスは次のように挿入されます。
angular.module('starter', ['ionic', 'starter.controllers',
'starter.services'])
最終的にはまだまだやらなければならないことがたくさんあるので、今すぐ確実に手に入れたいと思っています。
starter.controllers を適切に含めましたか? 複数ある場合、複数含める必要がありますか? それらは実際に index.html ファイルに含まれています。