gpt4 book ai didi

angularjs - Angular 用户界面选择 : How to bind only selected value to ng-model

转载 作者:行者123 更新时间:2023-12-04 01:16:35 24 4
gpt4 key购买 nike

$scope.property = new Property();
$scope.property.propertyType = {};

$scope.propertyTypes = [
{ value: 'ResidentialPlot', name: 'Residential Plot' },
{ value: 'CommercialPlot', name: 'Commercial Plot' },
{ value: 'Apartment', name: 'Apartment/Flat' },
{ value: 'Townhouse', name: 'Townhouse' },
{ value: 'House', name: 'Single Family House' },
{ value: 'Commercial', name: 'Commercial Property' }
];

<label for="ptype" class="col-sm-2 control-label">Property Type</label>
<p>Populated: {{property.propertyType}}</p>
<ui-select ng-model="property.propertyType" id="ptype" theme="selectize" ng-disabled="disabled" style="width: 300px;" title="Choose Property Type">
<ui-select-match placeholder="Select a Property Type">{{$select.selected.value}}</ui-select-match>
<ui-select-choices repeat="propType in propertyTypes">
<span ng-bind-html="propType.name"></span>
<small ng-bind-html="propType.value"></small>
</ui-select-choices>

这给了我:
$scope.PropertyType = {"value":"Apartment","name":"Apartment/Flat"}

我的架构中的 PropertyType 只是一个字符串,所以我想绑定(bind)选定的值而不是选定的 JSON 项。
$scope.PropertyType = "Apartment"

我应该绑定(bind)什么到我的 ng-model 来获得这个?

最佳答案

你不需要$watch。

<ui-select ng-model="property.propertyType" id="ptype" theme="selectize" ng-disabled="disabled" style="width: 300px;" title="Choose Property Type">
<ui-select-match placeholder="Select a Property Type">{{$select.selected.value}}</ui-select-match>
<ui-select-choices repeat="propType.value as propType in propertyTypes track by $index | filter: $select.search">
<div ng-bind-html="propType.value | highlight: $select.search"></div>
</ui-select-choices>

关于angularjs - Angular 用户界面选择 : How to bind only selected value to ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28142929/

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