1

After adding "multiple = true" to my select, it's adding an array of objects to the model instead of each object separately.

This is what I want:

{
    teams: [
      {name: 'team1'},
      {name: 'team2'},
      {name: 'team3'}
    ]
}

But instead I'm getting

{
    teams: [
      {name: 'team1'},
      {name: ['team2','team3']}
    ]
}

http://i.imgur.com/ILxWhpX.png

Pic of data structure issue.

2 Teams put in manually are objects. Teams put in using md-select are an array within an object.

$scope.baseGitblituser = {
    CODE HERE DELETED FOR READABILITY, WAS FOR OTHER USER FIELDS
    teams:
      [{name: "xignorex All Users"},
      {name: "Test Users"}]
};

This initiates the scope for the user and adds the global teams manually that all users will contain.

// this is created elsewhere using $scope.gitblitUser = angular.copy($scope.baseGitblituser);
$scope.gitblitUser.teams.push({name:user.team});

This is part of the function that is called when the md-select button is clicked to create a new user. This is how the teams array is updated with new teams.

  <md-select ng-model="user.team" multiple="true" name="teams" placeholder="your default team " style="min-width: 200px;">
         <md-optgroup label="">
               <md-option ng-value="team.name" ng-repeat="team in teams">{{team.name}}</md-option>
                            </md-optgroup>

This is the HTML portion.

17
  • Too many words, not enough code. Maybe i missed something in the text, but, i don't quite understand what exactly the problem here is. None of the code you have provided recreates what you mention in your title. Commented Oct 6, 2015 at 15:52
  • typo? $scope.baseGitblituser not the same as $scope.gitblitUser? or how does one become the other? Commented Oct 6, 2015 at 15:52
  • $scope.baseGitblituser is the scope that is preset for all users. I then use $scope.gitblitUser = angular.copy($scope.baseGitblituser); To copy that scope into the new one. I will edit that in my main post, thank you. Commented Oct 6, 2015 at 15:54
  • Gotcha. So when you select multiple, it's adding multiple, to a single team, rather than to the overall team array, right? Commented Oct 6, 2015 at 15:56
  • Basically, if you refer to the first picture.. is there a way to make md-select push in separate objects rather than an array in a nested object? Commented Oct 6, 2015 at 15:57

1 Answer 1

2

So the link that Kevin B referred me to might've worked... but it got a little interesting for me and changed up my html a lot. BUT! I saw the for loop in there... and even though it's used differently, it gave me the idea to try messing with a for loop to pull objects out of the array individually.

$scope.gitblitUser.teams.push({name:user.team}); 

Changed to -

for (var i=0; i < user.team.length; i++){ $scope.gitblitUser.teams.push({name: user.team[i]}); } 

So ultimately... your link helped spark the for loop thought - so thank you very much!

Thought I'd post this here incase anyone runs into the issue I did in the future.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.