我有这项服务:
function AddSuggestedPeersService($http, SITE_CONFIG) {
console.log("I come in Add Suggested Peers Service");
var addSuggestedPeers = this;
addSuggestedPeers.addSuggPeer = function(peerID, mode) {
// a service
return response;
}
}
然后我在控制器中使用它,如下所示:
peerHealthController.AddConfirm = function(peerID,mode,peerName){
console.log("I come in Add Confirm");
console.log("Peer ID =====" + peerID);
var confirmPopup = $ionicPopup.confirm({
title: '',
cssClass : 'confirmBox',
templateUrl: 'peers/add_peer_confirmation.template.html',
buttons: [{
text: 'NO, THANKS'
}, {
text: '<b>YES, PLEASE</b>',
type: 'button-yes',
onTap: function(e) {
e.preventDefault();
return AddSuggestedPeersService.addSuggPeer(peerID,mode);
}
}]
});
}
虽然它转到了服务但是无法调用该方法,但是说没有方法存在。
ionic.bundle.js:26794 TypeError: AddSuggestedPeersService.addSuggPeer is not a function
at Object.onTap (peersLandingPage.controller.js:108)
at ChildScope.$buttonTapped (ionic.bundle.js:56771)
at fn (eval at compile (ionic.bundle.js:27638), <anonymous>:4:386)
at ionic.bundle.js:65427
at ChildScope.$eval (ionic.bundle.js:30395)
at ChildScope.$apply (ionic.bundle.js:30495)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65426)
at defaultHandlerWrapper (ionic.bundle.js:16787)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16775)
at triggerMouseEvent (ionic.bundle.js:2953)(anonymous function) @ ionic.bundle.js:26794
我缺少什么语法?
答案 0 :(得分:0)
您没有退回任何服务。要解决此问题,只需返回变量&quot; addSuggestedPeersService&#39;那么你应该可以使用你服务的功能。
function AddSuggestedPeersService($http, SITE_CONFIG) {
console.log("I come in Add Suggested Peers Service");
var addSuggestedPeers = this;
addSuggestedPeers.addSuggPeer = function(peerID, mode) {
// a service
return response;
}
return addSuggestedPeers;
}