我正在为给定ID获取客户,客户详细信息是名称,电子邮件和客户类型{0,1}。 对于0,客户将为Regular,1将为Temporary。如何在控制器中使用ng-options时设置选项的值?
我能够在窗体上显示客户的详细信息,但能够选择客户类型。我的选择选项显示{'regular','temporary'},但不选择任何选项值。
例如
customer1={'name':'john', 'email':'[email protected]', 'customer_type':0}
形式能够显示的姓名和电子邮件,但不选择'常规' 选项
控制器
$scope.customers_type=['regular','temporary'];
//I will get details of customer
$scope.customer=getCustomer($scope.id);
if($scope.customer.customer_type ==0)
$scope.customer.type=$scope.customers_type[0]
else
$scope.customer.type=$scope.customers_type[1]
HTML
<div>
<label for="Name">Name </label>
<input ng-model='customer.name' name="Name" type="text">
</div>
<div>
<label for="email">Email </label>
<input ng-model='customer.email' name="email" type="text">
</div>
<div>
<label for="enterprise">Type of type of Customer </label>
<select ng-model='customer.type' type="text" ng-options="type for type in customers_type">
</select>
</div>
你*已经*获得期权的价值;也许你问的是如何获得物品的“索引”?即现在,'customer.type'可以等于* values *''regular''或''temporary'',但是你的模型有'0'和'1'。 – Claies
@Claies,是的,你是对的.. – geeks