我正在选择md-like:
<md-select ng-model="someModel" title={{someModel}}>
<md-option ng-value="opt.id" ng-repeat="opt in neighborhoods2">{{ opt.name }}</md-option>
它在title中显示了opt.id值。但我必须在title中显示opt.name。如何为所选值的名称添加title属性?
答案 0 :(得分:0)
for that you have to select object in ng-value like
<md-select ng-model="someModel" title={{someModel.name}}>
<md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt.name }}</md-option>
</md-select>
but make sure in your controller you will get an object so you have to get id as
if(angular.isString(someModel)){
var myValue= JSON.parse(someModel).id;
}
答案 1 :(得分:0)
您可以使用opt.name
对象本身作为值,而不是将值设置为opt
。这样,您的md-select
模型将具有所选项目的名称和ID。
这是一个codepen:https://codepen.io/standard/pen/JKKeEy