user3288891 user3288891 - 4 years ago 112
AngularJS Question

access selected option value outside scope of ng-repeat

I'm trying to access option value outside of ng-repeat scope .
here is jsFiddle

If you look at it, i can access id but not name. How can I access name outside scope of ng-repeat.

<div ng-controller="csrClrt">
<label>Face Style:</label>
<md-select ng-model="style" ng-change="f_style()">
<md-option ng-value="" ng:repeat="user in styles">{{}}</md-option>
<br/> Want to Display Name {{name}}


angular.module('MyApp', ['ngMaterial'])
.controller('csrClrt', function ($scope) {

var style=[];
for(var i=0;i<stylesdata.length;i++)

Answer Source

Just use ng-value="user" instead of ng-value="" and add ng-model-options="{trackBy: '$'}" to handle deep equality:

<md-select ng-model="style" ng-change="f_style()" ng-model-options="{trackBy: '$'}">
  <md-option ng-value="user" ng:repeat="user in styles">{{}}</md-option>

Working fiddle:

Also, see corresponding section in angular material documentation for reference

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download