When ng-model is updated, form radio buttons trigger memories from the past, causing ng-check to malfunction

Angular 1.*

Here is the code snippet:

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

This is what the controller holds:

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



  $scope.$watchCollection(function() {
    return ppvFilter;
  },
    function(newValue) {
      $scope.regions = newValue.regions;
      $scope.markets = newValue.markets;
      $scope.dealers = newValue.dealers;
  });

After refreshing the list of radio buttons programmatically (not through a page refresh) using the code

ppvFilter.markets.length = 0; ppvFilter.markets = ppvFilter.markets.concat(['a', 'b', 'c'])
, the radio button choices in the GUI update correctly. However, the ng-checked="true" attribute no longer works for the "all" option and it becomes unchecked after the list update.

It is believed that this issue arises because the Angular form is referencing old memory even though it displays the new radio button list.

Answer №1

The information provided in the angular documentation regarding the ngChecked directive advises against using it in conjunction with ngModel, as it may result in unforeseen outcomes.

Answer №2

After some investigation, I discovered that the default item must be within the ng-repeat for everything to work correctly. The ng-check directive doesn't really serve a practical purpose in this scenario.

For more information, please visit:

How to set a radio button as checked by default when using ng-repeat

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

Extensions for selecting and making Datatable responsive

Currently, I am working on integrating a Datatable into my products table. My goal is for it to be both responsive and include the select extension (checkbox for each column). I have successfully implemented both features. However, I noticed that when the ...

What is the best way to incorporate bullet points into a textarea?

How can I make a bullet point appear when pressing the 'enter' button inside a textarea? I tried using this code, but it doesn't seem to work. Any suggestions? <script> $(".todolist").focus(function() { if(document.getElementById( ...

What methods are available for retrieving specific XML entries using JavaScript?

Hey there, I'm dealing with this XML code <book> <bookname>book1</bookname> <author>authorman</author> </book> <book> <bookname>book2</bookname> <author>authorperson</author> </book ...

If I remove my project but still have it saved on my GitHub, do I need to reinstall all the dependencies or can I simply run npm install again?

I have a question regarding my deleted project that is saved on GitHub. If I formatted my PC and lost the project but it's still on GitHub, do I need to reinstall all the dependencies or can I just run 'npm install'? The project has dependen ...

jQuery .load() pause, content loading

Can anyone provide assistance with achieving the desired effect of fading out the #portfolio-wrapper, then loading the portfolio2.html and fading it in? Currently, the load function is executing before the fadeOut operation. Any help would be greatly app ...

Expansive full screen image proportions

Is there a way to showcase an image on the entire screen without distorting it, while maintaining its aspect ratio in either HTML or Javascript? The desired outcome is for the image to be centered and: - Have a height of 100% and a width of x% (where "x" ...

Identify whether the Vue model change was initiated by user input or programmatically

I am facing an issue with Vue's reactivity when using a custom component in Quasar 2. Let me explain the scenario: The custom component includes two radio buttons and a select dropdown. Whenever the user changes one of the radio selections, the selec ...

The gear icon in the video player is not showing up when I try to change the

I am currently trying to implement a feature that allows users to select the quality of the video. I am using videojs along with the videojs-quality-selector plugin, but even though the video runs successfully, the option to choose the quality is not appea ...

Forcing UTF-8 Encoding in JavaScript

I came across this helpful article: While following the advice of many others suggesting to use unescape(encodeURIComponent(srt)), I encountered issues. Attempting to convert the file obtained through XMLHttpRequest did not yield the desired results. Pri ...

How can I retrieve the input value on the current page using PHP?

Hey there, so I'm pretty new to PHP and I have a question. Is it possible to retrieve the input value from an existing input field on a page using PHP when the page loads, and then assign that value to a variable? For instance, let's say I have ...

What techniques can be used to avoid the MUI `DataGrid` from constantly re-rendering when a row is committed?

Check it out here to see how the MUI documentation implemented it: <b>const</b> rows = [/* Row Data */] <DataGrid rows={rows} {/* Other Props */} /> <sup>/*[1]*/</sup> The approach taken by MUI is quite impressive. It streaml ...

What is the best way to retrieve the first item in owl carousel's content?

I need help creating a slider with two sections: top and bottom. My goal is to display the content from the bottom slider on the top slider. I tried adding a class to the first item element, but it didn't work. If anyone knows how to target the first ...

What is the process for sending a json response from a function?

Currently, I am experimenting with Javascript, node js, and sails. I am in the process of learning and figuring out how to accomplish certain tasks. At the moment, I have a simple example that I am working on. My goal is to fetch a json using a rest call ...

A guide to retrieving all image URLs when a checkbox is selected using Javascript

My goal is to extract only image URLs from the concatenated values of price and picture URL. However, when I check different images using checkboxes, it always displays the URL of the first selected image. When I try to split the value, all the prices and ...

What is the best way to mix up the images in my memory game?

My JavaScript memory game is functioning properly, but I would like the images to load in a random order. Unfortunately, I'm not sure how to accomplish this. Here is the current setup: var easyImages = ["img/bat.jpg", "img/bug.jpg", "img/cat.jpg", " ...

Tips on displaying hyperlinks within a text area in an Angular application

In my Angular application, I am facing an issue with displaying hyperlinks within a text area box for dynamic content. The hyperlinks are not recognized and therefore cannot be clicked. Can someone please advise on how to properly display hyperlinks with ...

jQuery fade in problem or alternate solutions

When I send a post request to a file and input the response into id='balance', I would like it to have a flickering effect or fadeIn animation to alert the user that it is being updated in real time. I attempted to use the fadeIn() method but it ...

Text Parallax Effect

For my website, I am interested in incorporating a unique parallax effect. Instead of just fixing a background image and allowing scrolling over it, I want to apply this effect to all of the content on my site. The website consists of a single page with m ...

Extract the entire div including all its elements and then transmit it using the PHP mail function

Currently, I am developing a feature that allows users to send an email. The email should include only one div from the page which contains elements added using the jQuery drag and clone function. I am unsure how to copy the entire div along with its child ...

Place the image on the canvas

I currently have a canvas where I am able to add text layers and images from flickr. My goal is to enable users to upload an image to the canvas using the html input. For uploading images from flickr, I am using this code: $(".search form.image-search"). ...