我有一个带有选项的选择。我想初始化关于用户登录的选择值ng-init="own = credentials.user_id"
。
它在user_id
等于 中的值时起作用select
。但是当它不等于时,选择的值是"?"
。所以应该没有错误。
我不想选择这个"?"
并使表格无效。
你有解决方案吗 ?
<div ng-class="{ 'error-select': myForm.lead.$error.required == true }"><span>Leader</span></div>
<select ng-model="lead" name="lead" ng-options="leader.user_id as leader.user_display_name for leader in leaders" ng-init="lead = credentials.user_id" required></select>
<div ng-class="{ 'error-select': myForm.own.$error.required == true }"><span>Leader</span></div>
<select ng-model="own" name="own" ng-options="own.user_id as own.user_display_name for own in owns" ng-init="own = credentials.user_id" required></select>
输出:user_id = 4
<select t ng-model="lead" name="lead" ng-options="leader.user_id as leader.user_display_name for leader in leaders" ng-init="lead = credentials.user_id" required="" class="ng-pristine ng-valid ng-valid-required">
<option value="0">Alexandre</option>
<option value="1">Antoine</option>
<option value="2">Zaaza</option>
<option value="3">toro</option>
<option value="4"selected="selected">Steffi</option>
</select>
<select t ng-model="own" name="own" ng-options="own.user_id as leader.user_display_name for own in owns" ng-init="own = credentials.user_id" required="" class="ng-pristine ng-valid ng-valid-required">
<option value="?" selected="selected"></option>
<option value="1">Alexandre</option>
<option value="2">Steffi</option>
</select>