1

示例表格:

<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 &amp; 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](或它需要的任何属性)的同时接收?

我希望我的问题很清楚。提前喝彩。

4

1 回答 1

0

什么有效(@dfsq 提供)

相关的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]}}
于 2014-09-04T02:26:51.850 回答