示例表格
<select ng-model="coffee.location">
<option display-value='Some verbose message here' value="home">At home</option>
<option display-value='Some verbose message here' value="work">At work</option>
<option display-value='Some verbose message here' value="chain">Coffee Shop Chain (i.e. Starbucks & Costa)</option>
<option display-value='Some verbose message here' value="independent">Independent Coffee Shop</option>
</select>
显示元素示例:
<div>{{ coffee.location }}</div>
问题:
如何让我的Angular控制器接收option[value]
,同时{{coffee.location}}
显示option[display-value]
(或者需要的属性)?
我希望我的问题很明确。提前干杯。
答案 0 :(得分:0)
相关的javascript:
app.controller('SuggestionController', ['$scope', function($scope) {
$scope.stringMap = {
home: 'cosy up at home',
work: 'lounge at work',
chain: 'patrol the highstreet'
};
}]);
相关HTML:
<div id="some_parent" ng-app ng-controller="SuggestionController">
...
<select ng-model="coffee.location">
<option value="home">At home</option>
<option value="work">At work</option>
<option value="chain">Coffee Shop Chain</option>
<option value="independent">Independent</option>
</select>
...
</div>
{{stringMap[coffee.location]}}