Leveraging ng-model with expressions in ng-repeat in AngularJS.Would you

Currently, I am tasked with creating a form for a multilanguage content management system using angularJS.

The language list has been defined within the angular scope as follows:

$scope.languages = 
[
 {id:0,'name':'English'},
 {id:1, name:'French'}
  /* ... */
]

When attempting to create the form in my HTML, I encountered an issue:

<div ng-repeat="lang in languages">
    <label for="titlel{{ lang.id }}">{{ lang.name }}</label>
    <input type="text" class="form-control"  ng-model="editquestion['titlel{{ lang.id}}']" id="titlel{{ lang.id }}" />
</div>

Although the labels display correctly, the ng-model binding is not functioning properly. The text fields remain empty despite data being present in editquestion.titleX. Furthermore, any text inputted into one field is replicated across all fields.

Upon inspection, the ng-model attribute appears to be correct.

Screenshots of the issue can be viewed here:

This issue does not arise when manually coding the HTML, as seen below:


 <label for="textl0">English</label>
 <textarea class="form-control" ui-tinymce="tinymceOptions" ng-model="editquestion.textl0"></textarea>

 <label for="textl1">French</label>
 <textarea class="form-control" ui-tinymce="tinymceOptions" ng-model="editquestion.textl1"></textarea>

Answer №1

ng-model requires an expression (which is then assessed in the current scope), it functions differently compared to assigning an ID for a label. Consider modifying your input like this:

<input ... ng-model="editquestion['titlel' + lang.id]" />

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

Having trouble injecting $ionicHistory into my AngularJS controller

I am encountering an issue with using $ionicHistory.goBack() in a Controller within my Angularjs/Ionic application. Upon attempting to inject it into my controller as shown below app.controller('ClockInController', function($scope, $http, JobDat ...

Using JavaScript to generate dynamic folders in Alfresco is not functioning as expected

Working with Alfresco 4.0.d community edition (also tested on Alfresco 4.0.c) on an Oracle Linux 64-bit virtual machine using Firefox. I've been developing a script to dynamically create sub-folders as new items are added to a space/folder via a rule ...

Error message "Encountered an unknown type 'ForOfStatement' when attempting to execute an npm library"

Currently, I am in the process of integrating the PhotoEditor SDK library into my Ruby on Rails project. To achieve this, I have been meticulously following the installation guidelines provided in the official documentation. However, during the setup proce ...

Retrieving a universal variable within AngularJS

Is there a way to initialize an Angular model using a JSON object that is embedded within an HTML page? Take this as an example: <html> <body> <script type="text/javascript" charset="utf-8"> var tags = [{&q ...

What is the best way to send and configure GET information when the characters in a URI surpass 5,000?

Currently, I am utilizing a Laravel blade template. However, I encountered an error in my code when the size of the textarea item is quite large. I'm in search of a solution to resolve this issue. Hey everyone! Can you guide me on how to successfull ...

Discover how to retrieve service response data from an API and populate it into the Select Option with Angular 2

Api.services.ts getListOfNames() { return this.http.get(this.BaseURL + 'welcome/getnama') .pipe(map(response => { return response; })); } After making the API call, I receive the following resp ...

Adding data from a database into an object in PHP for temporary use during the loading process can be achieved by following

I'm a beginner in PHP and I have some code that retrieves category type data from a database. I want to temporarily store this data in a PHP object while the page is loading. Initially, I need to load all predefined data and then use it when a certain ...

Ways to extract metadata from a given URL

Recently, I've delved into the world of JavaScript and I'm looking to extract metadata from a given URL. Whenever a URL is entered into an input field, I want to retrieve its meta data - a simple task in HTML using JavaScript. However, every time ...

Contrasting the utilization of jQuery versus angular element references within an angular directive

Recently, I have been exploring ways to integrate jQuery into angular. One method I found was by utilizing the link function. $('#slider').slider(); However, I couldn't help but wonder about the disparity between the above code snippet an ...

What are the steps to create offline documentation for sails.js?

I am looking to integrate offline sails.js documentation into my system. You can find the official documentation for sails.js maintained at this Sails.js Documentation. According to their documentation, they use doc-templater for building the documentati ...

Tips for Customizing Dialogs with CSS Classes in mui5 Using Emotion/Styled

When attempting to customize the styling of a mui Dialog, I encountered an issue where it wouldn't accept className even when placed inside PaperProps. While inline styles worked, my preference was to import styles from a separate stylesheet named Sty ...

The issue of flickering during the combination of slideToggle and animate in jQuery

I want to incorporate a hidden div that, when triggered by a button click, will smoothly reveal itself and "push" away part of another div without changing the overall size of the containing div. However, I have encountered an issue where the div below th ...

IE8 encountering issues with Jquery ajax() request

My current issue involves submitting data using ajax from forms with a class of ajax. This functionality works flawlessly in Firefox, Safari, and Chrome, but is unsuccessful in Internet Explorer. ajax: function() { $('form.ajax').live(&apo ...

Creating a customized URL using the famous "@" symbol

Is it possible to set up a dynamic route in Next.js that includes the @ symbol? For instance, localhost:3000/@some_username I'm familiar with creating dynamic routes using the pages folder, but I'm not sure how to achieve this specific format w ...

Should we store $(this) in jQuery's cache, or leave it be?

When dealing with a selector such as $(this), does the act of creating and reusing a reference actually have a noticeable impact on performance? I find it more efficient to create references for jQuery selectors that are used repeatedly within the same sc ...

Is there a way to dynamically update text using javascript on a daily basis?

I am currently developing a script to showcase different content and images every day. While I have successfully implemented the image loop to display a new picture daily, I need assistance in achieving the same functionality for the title. My aim is to c ...

Discovering the Active Modal Form in BootStrap: Uncovering the Open Modal Form using JavaScript/jQuery

There are a total of 5 modal forms on my page. My goal is to identify the specific Id of the currently active one. One possible solution involves checking if $('#myModal').hasClass('in');. However, this method requires me to repeat the ...

Using jQuery to crop an SVG view box

I'm currently working on a sticker website project for a client who requires the ability to crop an image within a specific SVG shape, resembling a Halloween face (shown below). The uploaded image should be displayed only within this shape while hidi ...

Mongoose documents are set to automatically be deleted after a duration of one month

My goal is to retain a particular document for one month after the client-user deletes it. To achieve this, I have decided to simulate a delete action and display data in the browser. Sample schema: const product = new mongoose.Schema({ --- trash : { ty ...

Updating a table cell triggers a change in every cell

I have a table with columns and I need to calculate values in other cells when there is a change event on the table. I want to use ng-change so that the changes are seen immediately. However, I am unsure of how to properly utilize ng-model - if it is used ...