Troubleshooting why "ng-check="true" isn't functioning properly after radio choices update

Three columns of radio drop down boxes are present. When a user selects a radio button in the first column, the radio buttons in the second column refresh with a new list. The default behavior is for the top radio button all to be checked each time a new list is loaded into the second column. However, after the second refresh, the ng-check="true" does not apply and the all button is left unchecked.

Is there a way to ensure that the all button remains checked by default when the list of radio buttons in the second column is refreshed with a new list?

  <div class="filter-column">
    <div class="filter-title">Market</div>
    <div class="bottom-line"></div>
    <div class="overflow-container">
      <div ng-show="markets.length >= 1">
        <input type="radio" value="all" name="marketRadio" ng-checked="true" class="resetAll"
          ng-model="filter.market" ng-change="radioMap('market')">All
      </div>
      <div ng-repeat="choice in markets| orderBy: 'name'">
        <input type="radio" value="{{choice.name}}" name="marketRadio"
          ng-change="radioMap('market', $index)" ng-model="filter.market" >
        {{choice.description}}
      </div>
    </div>
  </div>

Here is the logic for when the second column of radio buttons is refreshed with a new list:

  var ppvFilter = {
    regions: [],
    markets: [],
    dealers: []
  };


  function populateMarkets(regionCode) {
    ppvFilter.markets.length = 0;
    ppvFilter.dealers.length = 0;
    var urlPath = API_BASE_URI + 'service/org/' +
      regionCode + "/markets";

    var params = {
      url: urlPath,
      method: 'GET'
    };

    $http(params)
      .then(function(response) {
        ppvFilter.markets = ppvFilter.markets.concat(response.data);
      })
      .catch(failure);
  }

Answer №1

The ng-checked attribute is being overridden by the ng-model value bound to the input. To ensure the checkbox is checked on page load, you can use ng-init="filter.market = true" to set filter.market as truthy.

Generally, when an ng-model is bound to an input, it will take precedence over any hardcoded attributes attempting to set the value. You must programmatically set filter.market to true for it to have an effect.

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

Downloading Files from Mongodb Using GridFS

I am working on an application that enables users to upload and download various files. Currently, I am facing a challenge where I am able to retrieve the file from my MongoDB database and download it locally on my machine, but I am encountering difficulti ...

Automatically save user input in form fields with the help of jQuery and AJAX technology

I'm working on a form that has various input fields, and I need the data entered by the user to be automatically stored in the database every minute. After the user submits the request, it will be processed in a struts file where database interactions ...

Manipulating data rows in a table using jquery

I have a button called #add that, when clicked, adds a new row to a table. The last cell of the newly inserted row contains a delete icon that, when clicked, should remove the entire row. I thought I had everything set up correctly, but for some reason, c ...

Tips for capturing all mobile events in Angular

Trying to capture all mobile events like touch and swipe, I have added event listeners at the document level: document.addEventListener('tap', trackTouchActivity, false); document.addEventListener('swipe', trackTouchActivity, false ...

Expanding the Element prototype with TypeScript

Is there a corresponding TypeScript code to achieve the same functionality as the provided JavaScript snippet below? I am looking to extend the prototype of the HTML DOM element, but I'm struggling to write TypeScript code that accomplishes this with ...

Creating a three-dimensional representation by projecting onto the surface of a sphere in ThreeJS

3D animation is a realm filled with numerous terms and concepts that are unfamiliar to me. I am particularly confused about the significance of "UV" in 3D rendering and the tools used for mapping pixels onto a mesh. I have an image captured by a 360-degre ...

ajaxStart - Display change inconsistency

These are some helpful comments to shorten and improve the readability of the code In my current project, I am using Javascript (Ajax) along with PHP (Laravel). I encountered an issue where I have set up two listeners in my ajax function. One listener is ...

Display specific column using ng-repeat

When attempting to filter an array of objects using ng-repeat based on a specific key or column, the key/column for filtering is determined by a selection from a dropdown menu. data-ng-model="selectedValue" // -> item.name The search term is entered i ...

Changing an array into an object in JavaScript without rearranging the keys

I have a collection { 1: {id: 1, first: 1, last: 5} 2: {id: 2, first: 6, last: 10} 3: {id: 3, first: 11, last: 15} } My goal is to reverse the order of items without rearranging the keys so that it looks like this: { 1: {id: 3, first: 11, last: 15} 2: { ...

Tips for including a hashtag in an AJAX request

When using ajax to send messages to the server in my chat application, I encountered an issue where everything after a hashtag is omitted. I attempted to address this by encoding the message, but it resulted in other complications in the PHP code. The enco ...

What is the best way to execute an inline function two times in a row

I'm currently utilizing Gametime.js to create a real-time world chat feature. All messages are kept in a database for storage. Interestingly, PubNub, which is used by Gametime.js, seems to require messages to be sent twice for them to actually go th ...

"Looking to display an image object retrieved from AWS S3 using a signed URL in Vue.js? Here's how you

<div v-for="(data, key) in imgURL" :key="key"> <img :src= "getLink(data)" /> </div> imgURL here is an array that contains file names. methods: { async getLink(url){ let response = await PostsService.downloadURL({ i ...

The delete button in the "Chip" component of React Material-UI is not functioning as expected

I'm having trouble with the "Chip" control and its "X" button functionality. Unlike the examples shown here: http://www.material-ui.com/#/components/chip Adding the "onRequestDelete" property does include the "X" button, but it doesn't respond t ...

Exploring methods to reload a parent window from a child window using PHP

After opening a popup window from a modal, I am now trying to refresh the page where my modal is located. I have attempted to write some code that I found here, but it doesn't seem to be working. Here is an example of what I have tried: // This fun ...

Linking query branches without encountering the "Exceeded the number of hooks rendered during the previous render" error

This apollo client utilizes a rest link to interact with 2 APIs. The first API returns the value and ID of a record, while the second API provides additional information about the same record. I combine this information to render the content without using ...

Removing Files in Angular with Laravel

Developing a RESTful web application using Laravel 5.2 for the back-end and AngularJS for the front-end has brought me to a challenging situation. While I am able to upload images successfully, deleting them is proving to be difficult. The uploaded files ...

I keep encountering an error that says "ReferenceError: localStorage is not defined" even though I have already included the "use

I have a unique app/components/organisms/Cookies.tsx modal window component that I integrate into my app/page.tsx. Despite including the 'use client' directive at the beginning of the component, I consistently encounter this error: ReferenceErr ...

Changing data automatically in PHP through radio buttons

As a beginner in PHP, I am working with 2 radio buttons where one is checked by default. When the page loads, I want to display content based on the default selected radio button. ...

The react-select onChange event fails to render when passed with certain props

I recently started using the select-react library, which can be found at So far, I have successfully mapped options to individual items from my itemList. The dropdown registers the selected option, but my ultimate goal is for the bar chart to render the c ...

Error: Service Liferay encountered an unexpected identifier causing a syntax error

Upon clicking on the button labeled "delete save" in the Chrome console, an error is encountered: "Uncaught SyntaxError: Unexpected identifier". Additionally, when this action is performed, an object is printed to the console revealing its data ({company ...