【发布时间】:2017-10-18 02:00:59
【问题描述】:
我正在尝试检查帐户类型的单选按钮。它在数据库中正确,但在我加载此页面时未显示。但是,当我单击单选按钮时,它会正确更新值并显示为已选中。
account.accountType 是一个枚举,有 3 个选项 internal = 0、customer = 1 或 proposal = 2。 它也可以在设置之前为空,然后不会检查任何内容。 我该怎么做?
我正在使用 angular 1.4.9 并使用 typescript 作为控制器。
<div class="form-group"
ng-class="{ 'has-error': accountForm.$submitted && accountForm.accountType.$invalid }">
<label for="customerName">Account type:</label>
<div>
<label class="radio-inline">
<input type="radio" name="accountType"
id="internal" value="0" ng-model="account.accountType"
ng-required="true" ng-checked="account.accountType == 0"> Internal
</label>
<label class="radio-inline">
<input type="radio" name="accountType"
id="customer" value="1" ng-model="account.accountType"
ng-required="true" ng-checked="account.accountType == 1"> Customer
</label>
<label class="radio-inline">
<input type="radio" name="accountType" id="proposal"
value="2" ng-model="account.accountType" ng-required="true"
ng-checked="account.accountType == 2"> Proposal
</label>
</div>
<p class="text-danger" ng-if="accountForm.$submitted && accountForm.accountType.$invalid">Please choose an account type</p>
</div>
【问题讨论】:
-
发布您的控制器代码以更好地理解。
标签: javascript angularjs typescript radio-button