【问题标题】:Manage error ng-if angular管理错误 ng-if 角度
【发布时间】:2016-12-15 10:48:09
【问题描述】:

我有一个带有选择选项的表单。如果值为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;

valid 也一样。

如何解决我的问题也出现没有价值?

非常感谢

【问题讨论】:

    标签: javascript angularjs angular-ng-if


    【解决方案1】:

    请检查api.basicAuth1是否未定义?

    你应该在你的控制器上全局声明api.basicAuth

    样本看起来像:

    function controllername($scope)
    {
     $scope.api = { basicAuth: "Yes" }
         .
         .
         .
         .
         // other codes
         .
         .
         .
         .
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2017-07-14
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多