另一个函数(JS服务)中的离子调用函数



嘿伙计们,所以我有以下问题:我正忙于一个项目的Ionic移动应用程序,我需要在我的一个服务中调用另一个函数中的函数 .js文件 (pushNotificationService.js(

这是代码:

checkForNewMessage: function () {
console.log("This is the regID : " + regID);
console.log($rootScope.regID);
var data =
{
"action": "push_messages",
"key": systemKey,
"data":
{
"action": "checkNewMessages",
"device_id": regID,
"key": systemKey
}
};
console.log(json_encode(data));
return $http.post(webserviceURL, json_encode(data))
.then(function (response) {
getMsgNotiLocation(); //this is the function not working
return response;
});
// getMsgNotiLocation();
},

编辑:这是getMsgNotiLocation((:

getMsgNotiLocation: function () {
$rootScope.showCounter = true;
//console.log("This is what gets returned with the regID : " + json_decode(JSON.stringify(window.localStorage.getItem(regID))));
var theMessagePage = json_decode(window.localStorage.getItem(regID));
for (var x in theMessagePage) {
if (theMessagePage[x].read != "true") {
console.log("We have gotten this far atleast : " + JSON.stringify(theMessagePage[x].page))
if (theMessagePage[x].page === "messages") {
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log(" Afkondigings Message recieved and message count : " + JSON.stringify($rootScope.afkondigMsgCount));
}
else if (theMessagePage[x].page === "calendar") {
$rootScope.kalenderMsgCount = $rootScope.kalenderMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log(" Calendar Message recieved and message count : " + JSON.stringify($rootScope.kalenderMsgCount));
}
else if (theMessagePage[x].page === "sponsor") {
$rootScope.sponsorMsgCount = $rootScope.sponsorMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("SPONSOR Message recieved and message count : " + JSON.stringify($rootScope.sponsorMsgCount));
}
else if (theMessagePage[x].page === "#/app/schools/2/Academics") {
$rootScope.akademieMsgCount = $rootScope.akademieMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Akademie Message recieved and message count : " + JSON.stringify($rootScope.akademieMsgCount));
}
else if (theMessagePage[x].page === "#/app/schools/3/Sport") {
$rootScope.sportMsgCount = $rootScope.sportMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Sport Message recieved and message count : " + JSON.stringify($rootScope.sportMsgCount));
}
else if (theMessagePage[x].page === "#/app/schools/4/Culture") {
$rootScope.kultuurMsgCount = $rootScope.kultuurMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Kultuur Message recieved and message count : " + JSON.stringify($rootScope.kultuurMsgCount));
}
else if (theMessagePage[x].page === "contact") {
$rootScope.kontakMsgCount = $rootScope.kontakMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Kontak Message recieved and message count : " + JSON.stringify($rootScope.Kontak));
}
else if (theMessagePage[x].page === "#/app/schools/5/Information") {
$rootScope.inligtingMsgCount = $rootScope.inligtingMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Inligting Message recieved and message count : " + JSON.stringify($rootScope.inligtingMsgCount));
}
else if (theMessagePage[x].page === "news") {
$rootScope.downloadsMsgCount = $rootScope.downloadsMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Aflaaibaar Message recieved and message count : " + JSON.stringify($rootScope.downloadsMsgCount));
}
else if (theMessagePage[x].page === "#/app/schools/1/Applications") {
$rootScope.aansoekMsgCount = $rootScope.aansoekMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Aansoekvorms Message recieved and message count : " + JSON.stringify($rootScope.aansoekMsgCount));
}
else if (theMessagePage[x].page === "wallet") {
$rootScope.beursieMsgCount = $rootScope.beursieMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Beursie Message recieved and message count : " + JSON.stringify($rootScope.beursieMsgCount));
}
else if (theMessagePage[x].page = "affiliates") {
$rootScope.besigheidMsgCount = $rootScope.besigheidMsgCount + 1;
$rootScope.afkondigMsgCount = $rootScope.afkondigMsgCount + 1;
$rootScope.msgcount = $rootScope.msgcount + 1;
console.log("Besigheidsforum Message recieved and message count : " + JSON.stringify($rootScope.besigheidMsgCount));
} else {
console.log("Everything failed please recheck the if statements");
}
} else {
//The same as if the condition is met but just a - instead of a + 
}
}
},

另一个函数工作100%(getMsgNotiLocation(((,因为它也在其他地方被调用。当我尝试执行应用程序时,出现以下错误: 引用错误: 未定义 getMsgNotiLocation

我只是不知道如何做到这一点,请提前感谢任何帮助!

我也知道代码之间的所有注释都是不好的,但在发布之前,我很好地清理了我的代码,它只是为了跟踪我在哪里做了什么

也许你可以尝试使用箭头函数

return $http.post(webserviceURL, json_encode(data))
.then((response)=> {
this.getMsgNotiLocation(); //this is the function not working
return response;
});

最新更新