gpt4 book ai didi

javascript - Angular.js : get different form {{display. value}} 和 $scope.value 来自相同的 ng-model

转载 作者:行者123 更新时间:2023-11-28 07:59:07 25 4
gpt4 key购买 nike

示例表单:

<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 Controller 接收 option[value],同时让 {{coffee.location}} 显示 option[display-value] >(或者它需要的任何属性)?

我希望我的问题很清楚。提前干杯。

最佳答案

什么有效(由@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]}}

关于javascript - Angular.js : get different form {{display. value}} 和 $scope.value 来自相同的 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25642552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com