Ensuring that md-select(s) created through ng-repeat are linked to the same model

<div ng-repeat="(key, value) in dataSet | groupBy: 'partner.partnerName'"> 
  <md-select ng-model="userName"   placeholder="{{ key }}" class="partnerUser" > 
    <md-option >{{ key }} </md-option>
    <md-option ng-repeat="chatMsg in value" value="{{chatMsg.role.userId}}">{{ chatMsg.role.userId }} </md-option>
  </md-select>
</div>

Using the code above, multiple mdSelect directives are being generated. However, only one mdSelect can be selected out of many, and the value should be assigned to the model ng-model="userName". Is there a way to bind with one mdSelect model that can be referred to later?

$scope.dataSet = 
[{userName:'user1',partner :{partnerId:'1',partnerName:'firstPartner'}},
{userName:'user2',partner:{partnerId:'2',partnerName:'secondPartner'}},
{userName:'user3',partner:{partnerId:'1',partnerName:'firstPartner'}},
{userName:'user4',partner:{partnerId:'2',partnerName:'secondPartner'}
}];

I have data like this, and based on partner ID, records will be added to different Md-selects.

Answer №1

To store the value, you can utilize value.username.

<div ng-repeat="(name, val) in dataSource | groupBy: 'parent.parentName'"> 
  <md-select ng-model="val.userName"   placeholder="{{ name }}" class="partnerUser" > 

Answer №2

<md-select ng-model="partnerDet" class="partnerUserList" placeHolder="-- Choose a Partner --">
  <md-option ng-value="value[$index].partner.partnerName" data-ng-repeat="(key,value) in dataSet | groupBy: 'partner.partnerName'">{{ key }}
  </md-option>
</md-select>

utilizing $index to connect values with variables.

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

Discover how to access the DOM after AngularJS directive rendering is finished

Looking to create a unique scroll pane component using an AngularJS directive? Check out this jsfiddle example for a basic prototype. Here is the concept behind my custom scroll pane: Directice code snippet: myApp.directive('lpScrollPane', ...

What is the best way to transform an array of objects in JavaScript?

I'm working with an array of objects that I need to transform into a table by pivoting the data. In other words, I am looking to generate a new array of objects with unique titles and nested arrays of key-value pairs. Can someone please assist me in a ...

Transitioning to TypeScript: Why won't my function get identified?

I am in the process of transitioning a functional JavaScript project to TypeScript. The project incorporates nightwatch.js Below is my primary test class: declare function require(path: string): any; import * as dotenv from "dotenv"; import signinPage = ...

Utilize React Material UI to elegantly envelop your TableRows

Currently, I am faced with a challenge involving a table that utilizes Material UI and React-table. My goal is to wrap text within the TableRow element, but all my attempts have not been successful so far. Is there anyone who knows the best approach to a ...

Improving Angular factory's counter with socket.io integration

I am currently working on a solution to automatically update the number of incoming data. I have set up a system to listen for incoming messages and count them in a factory: angular.module('app') .factory('UpdateCounter', ['s ...

Using TinyMCE editor to handle postbacks on an ASP.NET page

I came up with this code snippet to integrate TinyMCE (a JavaScript "richtext" editor) into an ASP page. The ASP page features a textbox named "art_content", which generates a ClientID like "ctl00_hold_selectionblock_art_content". One issue I encountered ...

"Assigning a value to an Angular directive within an ng-repeat loop

I've been trying to assign values from ng-repeat to a customized directive, but unfortunately, the value is being set outside of the repeater instead of inside it. HTML: var app = angular.module('testApp', []); app.controller('test ...

What is the issue with this asynchronous function?

async getListOfFiles(){ if(this.service.wd == '') { await getBasic((this.service.wd)); } else { await getBasic(('/'+this.service.wd)); } this.files = await JSON.parse(localStorage.getItem('FILENAMES')); var ...

Steps for embedding the code into your website

I'm facing an issue with integrating a .jsx file into my website. I tried testing it on a single-page demo site, but nothing is showing up. Can someone guide me through the steps to successfully integrate it onto my site? I've also attached the . ...

Using Ajax and Session Variables for a Worksafe Filter to selectively hide images

Creating a photography portfolio with some images containing nudity prompts the need to hide them by default until the user chooses to reveal them by clicking a "Toggle Worksafe Mode" button. To prevent "confirm form resubmission" errors when users naviga ...

Obtain the position and text string of the highlighted text

I am currently involved in a project using angular 5. The user will be able to select (highlight) text within a specific container, and I am attempting to retrieve the position of the selected text as well as the actual string itself. I want to display a s ...

What causes SomeFunction.prototype to appear as "SomeFunction {}" when viewed in the console?

This is the code snippet: function Person(){} console.log(Person.prototype); // Person {} console.log(Person.prototype instanceof Person); // false console.log(Person.prototype instanceof Object); // true The output shows Person {} for Person.prototype, e ...

Upcoming examination on SEO using React testing library

Currently, I am in the process of testing out my SEO component which has the following structure: export const Seo: React.FC<Props> = ({ seo, title, excerpt, heroImage }) => { const description = seo?.description || excerpt const pageTitle = s ...

Is there a way to eliminate the border of an image attribute pulled from an input field?

Seeking assistance with a persistent issue I'm facing. I have an input for an image and a script to display the selected image. However, when the input is empty, a frustrating black border appears around the image attribute. How can I remove this bord ...

Adding a div element to a React component with the help of React hooks

I'm currently diving into the world of React and experimenting with creating a todo app to enhance my understanding of React concepts. Here's the scenario I'm trying to implement: The user triggers an event by clicking a button A prompt app ...

I'm curious if it's possible to modify a webpage loaded by HtmlUnit prior to the execution of any javascript code

To begin, I want to elaborate on the reasoning behind my question. My current task involves testing a complex web page using Selenium + HtmlUnit, which triggers various JavaScript scripts. This issue is likely a common one. One specific problem I encount ...

Having trouble getting Javascript to reveal hidden elements based on their class

I am having some trouble making specific fields in a form appear based on the selection made from a dropdown menu. Below is a simplified snippet of my code, which should change the display from 'none' to 'block'. Can you help me figure ...

Navigate through a given value in the event that the property undergoes a name change with each

Exploring an example found on the JSON site, I am facing a situation where I am using an API with JSON data. The property name "glossary" changes for each request made. For instance, if you search for "glossary", the first property is glossary. However, if ...

I am experiencing an issue where the jquery sleep function is not being executed during

I currently have an Ajax request that is awaiting a response from another process. function checkProcess() { var flag = 0; while (flag === 0) { $.ajax({ url: "cs/CheckForProcess", async: false, success: ...

Passing a Value from Child to Parent Function in Meteor: A Complete Guide

I am trying to pass the value of a result from a child element to its parent element. Initially, I used Session.set and Session.get which worked fine but I realize that using Sessions globally is not considered good practice. So, I attempted to utilize rea ...