我正在嘗試調用函數deleteConv
,該函數在$ ionicActionSheet中服務ChatsService
中,但失敗。我有一個錯誤Error: ChatsService.deleteConversation(...) is undefined
即使服務定義和注入控制器
/**
Controller
**/
angular.module('Tot.controllers')
.controller('MessageController', function($scope, $timeout,ChatsService,$localStorage,,Globals,$ionicActionSheet,Messages) {
var iduser=$localStorage[Globals.USER_LOGGED].id;
$scope.onConversationHold = function(e, itemIndex, conversation) {
$ionicActionSheet.show({
cancelText:'<span class="no-text-transform">Annuler</span>',
destructiveText: '<span class="no-text-transform">Supprimer</span>',
destructiveButtonClicked: function() {
ChatsService.deleteConversation(conversation,iduser).then(function(response){
alert(response);
return true; //Close the model?
})
}
});
};
});
/**
ChatsService.js
**/
angular.module('Tot.services')
.service('ChatsService', function($q,$http,Globals) {
var url=Globals.urlServer+Globals.port;
this.deleteConversation=function(conversation,iduser){
var deferred=$q.defer();
$http.get(url+'/conversation/deleteConversation?idconversation='+conversation+'&iduser='+iduser).success(function(response){
if(response)
{
deferred.resolve(response);
}
});
}
});
我怎樣才能解決呢?
將帖子
/**
app.js
**/
angular.module('Tot', ['ionic','Tot.controllers','Tot.services','Tot.constants'])
.run(function($ionicPlatform,Messages,$rootScope,$cordovaStatusbar, $state,Globals,$localStorage,$mdDialog,$mdToast) {
$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.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
//StatusBar.styleDefault();
$cordovaStatusbar.overlaysWebView(true);
$cordovaStatusbar.styleHex('#c62828')
}
....
})
很確定你應該注入你的服務到你的模塊中,你可以做一個codepen或張貼更多的代碼嗎? –
@JessPatton我用整個控制器和服務更新了我的問題 – Pisix