i add notification , handle receive notification event in app.js-->$ionicplatform.ready function. tab has own tabctrl , tab badge gets value badgeservice.
once receive notification, in app.js-->$ionicplatform.ready-->onreceive func, update service badge value.
but problem after update badge number badgeservice in app.js, tab badge not updated right away, when switch other tab, update.
so why service data change not update tabctrl scope value? because updating service badge in app.js not trigger tabctrl?
btw, bind tab badge value through service function avoid $broadcast , have tried $broadcast in app.js , $on in tabctrl, works, i'm afraid not best practice.
here how define tabctrl:
angular.module('app').controller('app.tabs.tabscontroller', function ( $scope, $rootscope, badgeservice) { $scope.badges =function(){ return badgeservice.setbadgecount(); } }])
tab.html:
<ion-tab title="message" icon-on="ion-social-buffer-outline positive" icon-off="ion-social-buffer-outline" href="#/tab/message" badge="badges()" badge-style="badge-assertive"> <ion-nav-view name="message"></ion-nav-view> </ion-tab>
badgeservice:
app.factory('badgeservice', function (localstorageservice) { var setbadgecount = function () { var count = 0; var badgeinfos = localstorageservice.get('badgeinfo'); if (badgeinfos) { (var = 0; < badgeinfos.length; i++) { count += badgeinfos[i].msginfos.length; } } if (count > 0 && count <= 99) { return count.tostring(); } else if (count > 99) { return "99+"; } else { return ""; } } return { setbadgecount: setbadgecount } })
app.js:
$ionicplatform.ready(function () { var onreceivenotification = function(){ badgeservice.setbadgecount(); })
i have created codepen code above. , works.... quite strange, why app not behave this... wants reference, pls check this:
//check link: http://codepen.io/sylfree9999/pen/gzyjae
Comments
Post a Comment