ngModel and ngRepeat allow for easy manipulation and iteration of properties

Here is a sample HTML code:

<div ng-repeat="item in items()">
    <input type="checkbox" ng-model="anObject[item.name]">
</div>

I am trying to access a property that depends on the item.name within my $scope.anObject which I defined in my controller. However, neither of the attempts above seem to work.

<div ng-repeat="item in items()">
    <input type="checkbox" ng-model="anObject.{{item.name}}">
</div>

UPDATE: You can check out a working example here.

Answer №1

The items() function causing the array to be returned, along with the ng-repeat, leads to a recursion issue. This interferes with the $digest cycle. If you simply bind the array to a scope variable instead of returning it, everything will work smoothly ;)

Check out this example.

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

regarding unfamiliar functions in code and their mysterious purposes

My journey learning Vue.js has been going well, but I've hit a roadblock. Can someone explain the meaning of _. in the following code snippet? ...

Steer Your Way: How to Redirect to a Different Router or Middleware in Node.js and Express.js

I'm creating an application using VENoM stack, and I have set up some middleware in the API like this: const express = require('express'); const router = express.Router(); require('./routes/orderRoutes')(router); require('./ ...

What methods are most effective for exchanging data between AngularJS and MVC5?

I'm facing some challenges when it comes to transferring data between AngularJS and MVC5 in the context of creating a single page application (SPA). What is the most effective way to integrate AngularJS with MVC - using controllers or APIs? I came a ...

AngularJS Assessing an Attribute directive following an Element directive

Currently, I am utilizing an angular plugin that can be found at the following link: https://github.com/angular-slider/angularjs-slider The objective is to customize the "legends" produced by the directive. In order to achieve this customization, the dire ...

Is it possible to determine if NPM install is functioning correctly in various situations or does it vary?

npm init is the first step to start a project I have specified axios: "~1.2.4" in my package.json file When I execute npm install, it installs version 1.2.6, updating to the latest patch as expected If I use ^1.2.4 in package.json and run npm in ...

Having trouble rendering a private route screen in React, while all the other screens work perfectly

I am encountering an issue with my Private Route in React where it fails to render, while every other screen renders successfully. I have set up the Private Route to render my PrivateScreen.js component, everything seems to be set up correctly but I cannot ...

Having Trouble Importing a Dependency in TypeScript

My experience with using node js and typescript is limited. I attempted to include the Paytm dependency by executing the following code: npm install paytmchecksum or by inserting the following code in package.json "dependencies": { ... & ...

Clicking inside the bootstrap modal does not trigger the ng-click event

I encountered an issue while trying to implement the "ng-click" function from Angular into an HTML page. It worked initially, but when I tried using the same "ng-click" function within a Bootstrap modal, the code stopped functioning. Can anyone explain why ...

Struggling to find a solution to adjust an Angular directive

I am attempting to create a functionality where, upon clicking a button, the user can select one of two images displayed and make the selected image draggable. Currently, my code displays two images with only one being draggable. I am struggling to impleme ...

Adding hyperlinks that do not redirect

I have 2 separate divs displayed on a website: <button class="form-control margin btn btn-warning hide_all" id="addLinks">Link Pages</button> <button style="display: none" class="form-control margin btn btn-primary hide_all" id="hideLinks"& ...

Improvement in Select2 Change Event: Update the subsequent select2 box options based on the value change in the preceding select2 box

I need assistance with two select boxes, namely Category and Sub-category. My objective is to dynamically alter the available options in the subcategory box based upon the value selected in the category box. Additionally, I would like to load data for the ...

Exploring Angular 6: Unveiling the Secrets of Angular Specific Attributes

When working with a component, I have included the angular i18n attribute like so: <app-text i18n="meaning|description"> DeveloperText </app-text> I am trying to retrieve this property. I attempted using ElementRef to access nativeElement, bu ...

Retrieving the function or state of a component within a higher-order component (HOC) wrapper

Hey there! I have a situation where Component A, which extends React.component, is wrapped with a higher order Component B. Now, in the methods of Component B, I need to either setState for Component A or call a function in A to do the setState. How can I ...

Steps for redirecting to an external URL with response data following an HTTP POST request:

this.http.post<any>('https://api.mysite.com/sources', [..body], [...header]) .subscribe(async res => { const someData = res.data; const url = res.url; window.location.href = url }) After redirecting to the specified UR ...

Enhancing Image Quality with jspdf and Html2Canvas

We are currently utilizing jsPDF and HTML2canvas to create PDFs, however, we have noticed that the image resolution is quite high. Is there a method available to obtain low-resolution images using jquery, javascript, jsPDF, and html2canvas? function addE ...

Obtain decrypted information from the token

I am facing difficulty in retrieving decrypted user data for the current user. Every time a user logs in, they receive a token. After logging in, I can take a photo and send it to the server. Looking at my code, you can see that this request requires a to ...

How to Implement a Count Filter for Filtered Items in AngularJS

I have a requirement to display subsets of a list when a checkbox is selected. Instead of an X next to the checkbox, I want to show the count of items in the list that meet the selection criteria. Everything works in my Plunker example except for counting ...

The Angular application sent an OPTIONS request instead of a POST request via HTTP

I'm encountering CORS errors while attempting to send HTTP requests from my angular.js application to my server. The code used to make the HTTP request is as follows: functions.test = function(foo, bar) { return $http({ method: 'POS ...

Using Redux to Implement Conditional Headers in ReactJS

I am planning to develop a custom component named HeaderControl that can dynamically display different types of headers based on whether the user is logged in or not. This is my Header.jsx : import React from 'react'; import { connect } from &a ...

Success/Fail Page for Form Redirect

I've been struggling to figure out how to redirect my form to a success or fail page. I've scoured the internet for solutions, looking into traditional form redirects and even JavaScript onClick redirects. Can someone guide me on adding a redirec ...