我有一个带有选择选项的表单。如果值为yes,我会显示div。当我验证我的表单时,没有出现。
<div class="row">
<div class="col-md-6">
<div class="form-group" ng-class="{ 'has-error': invalid.backendIntegrationUrl, 'has-success': valid.backendIntegrationUrl}">
<label for="backendIntegrationUrl">backend service URL *</label>
<input type="text" name="backendIntegrationUrl" class="form-control" placeholder="example: https://qualif.myapi.com/myapi/v1 " ng-model="api.backendIntegrationUrl" ng-required="true">
<span id="helpBlock" class="help-block" ng-show="help.backendIntegrationUrl.required">backend service URL is required.</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group" id="basicAuth">
<label for="basicAuth">basic auth info</label>
<select name="basicAuth" class="form-control" ng-init="api.basicAuth = api.basicAuth || 'no'" ng-model="api.basicAuth" id="basicAuth" >
<option value="no">no</option>
<option value="yes">yes</option>
</select>
</div>
</div>
</div>
<div class="row" ng-if="api.basicAuth == 'yes'" id="yesAuth">
<div class="col-md-6" ng-class="{ 'has-error': invalid.basicAuthForBackendUsername, 'has-success': valid.basicAuthForBackendUsername}">
<div class="form-group" >
<label for="basicAuthForBackendUsername">basic auth username *</label>
<input type="text" id="basicAuthForBackendUsername" name="basicAuthForBackendUsername" class="form-control" placeholder="basic auth username" ng-model="api.basicAuthForBackendUsername" ng-required="api.basicAuth =='yes'">
<span id="helpBlock" class="help-block" ng-show="help.basicAuthForBackendUsername.required">basic auth username is required.</span>
</div>
</div>
<div class="col-md-6" ng-class="{ 'has-error': invalid.basicAuthForBackendPassword, 'has-success': valid.basicAuthForBackendPassword}">
<div class="form-group" >
<label for="basicAuthForBackendPassword">basic auth password *</label>
<input type="text" id="basicAuthForBackendPassword" name="basicAuthForBackendPassword" class="form-control" placeholder="basic auth password" ng-model="api.basicAuthForBackendPassword" ng-required="api.basicAuth =='yes'">
<span id="helpBlock" class="help-block" ng-show="help.basicAuthForBackendPassword.required">basic auth password is required.</span>
</div>
</div>
</div>
我有一个验证函数,验证或不验证表格:
$scope.help = {};
$scope.invalid = {};
$scope.invalid.version = $scope.userForm.version.$invalid;
有效的是相同的。
我怎样才能解决我的问题,看似没有价值?
非常感谢
答案 0 :(得分:0)
请检查api.basicAuth1
是否未定义?
您应该在控制器上全局声明api.basicAuth
。
示例如下:
function controllername($scope)
{
$scope.api = { basicAuth: "Yes" }
.
.
.
.
// other codes
.
.
.
.
}