I have a table view, when I click one cell will call my PixCtrl
controller. If I check connection work, I will get data by $http.get
, if not I will use sqlite. This is work. I want my ion-nav-buttons
is dynamic. But when I first click, that is not work. I must do it again that will show. I have no idea how to fix it. and I had use console to watch it, and that is correct each time, how can I fix it for the first click.
thanks your help.
controller
.controller('PixCtrl', function($scope, $sce, $stateParams, SQLService, $http....) {
...
if ( ! $rootScope.noConnection) {
$http.get('http://pixnettest-lighter.c9.io/content.php?id=' + $stateParams.pixnetId)
.success(function(data, status, headers, config) {
var pix_data = {
...
html_comment_count: datas[0].comment_count,
...
};
$scope.pix_content = pix_data;
});
}
else {
// get by sqlite data
var pixnet_data = {
...
html_comment_count: content.comment_count,
...
};
$scope.pix_content = pix_data;
}
...
$scope.checkMComBtn = function(comment_count) {
var intValue = parseInt(comment_count) || 0;
console.log('intValue ' , intValue);
if (intValue > 0) {
return 1;
}
else {
return 0;
}
}
});
view
<ion-view on-swipe-right="onSwipeRight()" ng-init="initEvent()">
<ion-nav-buttons side="right" ng-if="checkMComBtn(pix_content.html_comment_count)">
<button class="button">Message</button>
</ion-nav-buttons>
...
</ion-view>
I founded this reason! I just modify ng-if
to button
, and that work!
<ion-view on-swipe-right="onSwipeRight()" ng-init="initEvent()">
<ion-nav-buttons side="right">
<button class="button" ng-if="checkMComBtn(pix_content.html_comment_count)">Message</button>
</ion-nav-buttons>
...
</ion-view>