Having trouble with the ionic ion-nav-buttons not working on initial load?

My table view triggers the PixCtrl controller when a cell is clicked. If the connection is successful, data is retrieved using $http.get, otherwise sqlite is used. This setup works fine. However, I am facing an issue with my ion-nav-buttons being dynamic. Initially, it does not work on the first click; only after clicking again will it show up. I have tried monitoring it through the console and everything seems correct each time. How can I resolve this problem with the first click?

Thank you for your assistance.

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 data from sqlite

      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>

Answer №1

After some experimentation, I discovered the solution! By changing ng-if to button, everything started working perfectly!

<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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The wrapper passes ngModel to the child directive

Let's consider a scenario where we have a child directive <child/> that utilizes both ng-model and ng-change to perform specific actions. There are also two types of wrapper directives, <w1/> and <w2/>, each containing the <child/ ...

I have discovered some amazing jQuery image hover effects that are simply breathtaking –

I have been using the Adipoli jQuery Image Hover Effects plugin, but I am facing issues with changing certain properties. The image is set to change to grayscale initially and then switch to color on hover. However, when I click on the image, it should mai ...

The operation of executing `mongodb - find()` does not exist as a function

I am having trouble printing all documents from the "members" collection. I attempted to use the find() function, but encountered an error stating that find() is not a function. Here is a snippet from member_model.js located in the models/admin folder: v ...

A single snippet of JavaScript blocking the loading of another script

I've encountered an issue where the code seems to be conflicting with itself. The top part works fine, but the bottom part doesn't. However, when I remove the top portion, everything works as intended! You can see a working example of both compo ...

Having trouble getting unique input values to pass through ajax

For the past couple of weeks, I've been searching for a solution to my issue. The problem arises in my PHP foreach loop where I have div tags representing rows of data fetched from the database. Each div row contains HTML input elements and a button t ...

What is the reason for a type narrowing check on a class property failing when it is assigned to an aliased variable?

Is there a way to restrict the type of property of a class in an aliased conditional expression? Short: I am trying to perform a type narrowing check within a class method, like this._end === null && this._head === null, but I need to assign the r ...

When utilizing json.loads in Python 2.7, it yields a unicode object rather than a dictionary

I'm currently facing a challenge with converting JSON data into a dictionary, and I'm struggling to find a solution. My situation involves connecting to a Tornado websocket from JavaScript and sending the following data inputted into a textfield ...

Unable to sort array within a computed property in Vue.JS

Currently, I am working on enhancing my skills in Vue.js and have encountered an issue with sorting arrays in Vue.js. Despite using the sort(a-b) method for ascending order (least alphabet/value first), the array remains unchanged. Even with a function ins ...

Exploring the Power of Destructuring Results in React.js with Apollo

I have been exploring the Apollo client for my project, and I encountered an issue with two of my query functions. The first query, which retrieves a list of users, is working perfectly fine. However, I am struggling to understand why my second simple quer ...

Using Jquery to duplicate a row from one table and insert it into another table

Recently, I've dived into the world of jQuery and JavaScript with the goal of creating a simple app. The main functionality I'm trying to implement is the ability to copy a row from one table to another and then delete the original row when a but ...

Enable AngularJS to automatically redirect to the login page when a user is not authenticated,

EDIT: I need to mention that my experience with AngularJs is only a week, so if you have any suggestions unrelated to the question itself, please feel free to share them in the comments section. Alright, here's the situation. I have authentication Co ...

Guide on submitting a form via Ajax on a mobile app

Looking for a way to submit the form located in components/com_users/views/login/tmpl/default_login.php using Ajax. <form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post"> <fie ...

Does this Loop run synchronously?

Recently, I crafted this Loop to iterate through data retrieved from my CouchDB database. I am curious whether this Loop operates synchronously or if async/await is necessary for proper execution. database.view('test', 'getAllowedTracker&ap ...

Can you explain the exact purpose of npm install --legacy-peer-deps? When would it be advisable to use this command, and what are some potential scenarios where it

Encountered a new error today: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1cfc4d9d5d5d6c8cfe1918f908f91">[em ...

What is the mechanism behind declaring a function using square brackets in Node.js/Javascript?

Encountering something new while working with Node.js - a unique way of declaring functions. You can find an example at this link. 'use strict'; const Actions = { ONE: 'one', TWO: 'two', THREE: 'three' }; clas ...

Troubleshooting the issue of post-initialization store updates not functioning in AlpineJS

When setting up a store, I initially use: document.addEventListener('alpine:init', () => { Alpine.store('selectedInput', 0) }) However, when attempting to update selectedInput within a function later on, it doesn't reflect th ...

Storing Radio Buttons and Checkboxes Using LocalStorage: A Simple Guide

Is there a way to save and retrieve values from localStorage for input types "radio" and "checkbox"? I've tried using the same code that works for text and select elements, but it doesn't seem to be saving the values for radio and checkbox. Can s ...

What is the method for creating an array of strings in VueJS?

In my VueJS and Vuetify project, I am working on creating a modal that allows users to input strings into a text field. What I aim to achieve is adding the inputted string to an array when the user clicks on create button. For example, if I enter 'inp ...

What is the best way to update configuration settings such as the host name when deploying with Gulp?

Currently developing a web application with AngularJS and utilizing Gulp for the build process. The app retrieves data from various APIs within AngularJS. However, a challenge arises during deployment as I need to use different host names depending on whet ...

Assistance needed with selecting elements using jQuery

After some practice with jQuery, I managed to select this specific portion from a lengthy HTML file. My goal is to extract the values of subject, body, and date_or_offset (these are name attributes). How can I achieve this? Let's assume this snippet i ...