我正在尝试调用函数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