Can anyone help me with setting a default drop-down value using JavaScript? I have been struggling to achieve this.
You can find my code on jsFiddle
<div ng-controller="csrClrt">
<div ng:repeat="(key, item) in items track by $index">
<md-input-container>
<label>Face Style:</label>
<md-select ng-model="item.style" ng-change="f_style()" ng-model-options="{trackBy: '$value.id'}">
<md-option ng-value="user" ng:repeat="user in styles">{{user.name}}</md-option>
</md-select>
</md-input-container>
<div>
Id:{{item.style.id}}
<br/> Want to Display Name {{item.style.name}}
</div>
</div>
</div>
JavaScript Code
angular.module('MyApp', ['ngMaterial'])
.controller('csrClrt', function ($scope) {
stylesdata = [{
name: "a",
id: 0
}, {
name: "b",
id: 1
}, {
name: "c",
id: 3
}
];
$scope.items = ["0"];
var style = [];
for (var i = 0; i < stylesdata.length; i++) {
style.push({
name: stylesdata[i].name,
id: stylesdata[i].id
})
}
$scope.styles = style;
})