根据选择值宽度显示/隐藏输入文本ng-model-options =" {updateOn:' submit'}"

时间:2016-09-12 17:42:34

标签: angularjs angular-ngmodel

我对AngularJS有疑问,但我还没找到帮助我的工具。我有一个选择框来选择状态。

我需要更新我的" ng-model"当我提交表格时,所以ng-model-options在这里很好。

我的问题是,如果我的选项是" status_2"我需要显示输入文字:

<ul>
  <li ng-repeat="product in products">

   <form>

    <select ng-model="product.myStatus" class="form-control" ng-model-options="{updateOn: 'submit'}" required>
      <option value="status_1">{{'status_1' | translate}}</option>
      <option value="status_2">{{'status_2' | translate}}</option>
    </select>

    <div ng-show="product.myStatus == 'status_2'">
      <input type="text" ng-model="product.comment" class="form-control" ng-required="product.myStatus == 'status_2'">
    </div>

    <input type="submit" />

   </form>

  </li>
</ul>

但它不起作用。输入文字不会出现。我知道为什么,但我不知道如何做到这一点,如果我能以另一种方式做到这一点。

我的AngularJS版本是1.5.5。

3 个答案:

答案 0 :(得分:0)

ng-model-options表示模型仅在您点击提交时更新。我不认为你想要这个。

-------------------------原始评论-------------

我不确定ng-model-options是什么,但当我删除它时,显示/隐藏更新很好:

                <select ng-model="product.myStatus" class="form-control" xxxng-model-options="{updateOn: 'submit'}" required>
                  <option value="status_1">{{'status_1'}}</option>
                  <option value="status_2">{{'status_2'}}</option>
                </select>

答案 1 :(得分:0)

模型在'submit'上更新。我想你可以尝试ng-model-options="{updateOn: 'blur'}"模型值会在'模糊'上改变。

答案 2 :(得分:0)

考虑一下。使用产品的副本进行循环。然后,在验证和提交时,将产品更新为新值:

HTML:

        <li ng-repeat="product in temp">

JS:

        $scope.products = [{myStatus: "status_1"},{myStatus: "status_2"}];
        $scope.temp = angular.copy($scope.products);


        $scope.submit = function(){
            $scope.products = angular.copy($scope.temp);

        }
相关问题