关闭模式

时间:2018-07-21 07:26:19

标签: javascript angularjs

我有两种不同形式的形式。当我打开第一个模态时,我console.log已附加到$scope的表格中(我的意思是,在开始时我给了$scope.updateSecurityForm = {}的控制器)并给出了{{1 }},然后看到所有属性,例如name="updateSecurityForm"等。我

当我打开第二个模态并再次$valid打开第一个模态的窗体时,该对象为空。然后,我关闭第二个模态,然后再次打开第一个模态,并在控制台中看到,我再次看到一个空对象。我希望看到表单属性,但是只有一个空对象。

模态的第一种形式:

console.log

第二种模式:

<div class="modal-body">
  <form name="updateSecurityForm" ng-submit="updatePersonnels(upObj, updateSecurityForm)" ng-repeat="upObj in personnelProfileData" novalidate>
    <div class="col-md-4">
      <label for="vendor-name" class="control-label">Vendor Name:</label>
      <select name="vendorname" ng-model="upObj.vendor_id" class=" text-center form-control" ng-options="data.vendor_id as data.vendor_name for data in getvendetailsdata">
        {{data.vendor_name}}
      </select>
    </div>
  </form>
</div>

这两个模态都在同一页面中,并且它们大部分相似。我在表单中使用了相同的<div class="modal-body"> <form name="addPlumberForm" ng-submit="addPersonnelsByRole(addObj,8, addPlumberForm)" novalidate> <div class="col-md-4"> <div class="form-group"> <label for="message-text" class="control-label"> Name of the vendor:<span style="color: red;">*</span> </label> <select class="text-center form-control ng-valid ng-empty ng-dirty ng-touched" name="vendorname" ng-model="addObj.vendor_id"> <option value="" selected="selected">- Please select a vendor name - </option> <option ng-repeat="ae in getvendetailsdata" value="{{ae.vendor_id}}" class="ng-binding ng-scope">{{ae.vendor_name}}</option> </select> </div> </form> </div> </div> ,以便于验证。

在我的控制器中,一开始我有

name$scope.updateSecurityForm = {},如果这对阅读的人来说很重要。

进行验证时,我会得到$scope.addPlumberForm = {}

Cannot read property '$invalid' of undefined

调用validate函数:

$scope.addPersonnelValidation = function(formName) {
    console.log(formName, "formName");
    if (formName.vendorname.$invalid) {
      $.bootstrapGrowl('Please select vendor name', {
        type: 'danger',
        delay: 2000,
      });
      return;
    }

1 个答案:

答案 0 :(得分:0)

我将所有代码都放在jsfiddle中,它没有给出未定义的错误。尽管您需要进行一些更正才能使验证生效。 我在最后提供了jsfiddle链接。让我知道这是否有帮助

    您选择的第二个模式中缺少
  • 必填属性。
  • 在表单标记上方的第二个模式中缺少div。

<div class="modal-body">
   <form name="addPlumberForm" ng-submit="addPersonnelsByRole(addObj,8, addPlumberForm)" novalidate>
      <div class="col-md-4">
         <div class="form-group">
            <label for="message-text" class="control-label">Name
            of the vendor:<span style="color: red;">*</span>
            </label>
            <select
               class="text-center form-control ng-valid ng-empty ng-dirty ng-touched"
               name="vendorname" ng-model="addObj.vendor_id" required>
               <option value="" selected="selected">- Please
                  select a vendor name -
               </option>
               <option ng-repeat="ae in getvendetailsdata"
                  value="{{ae.vendor_id}}" class="ng-binding ng-scope">{{ae.vendor_name}}</option>
            </select>
         </div>
         <input type="submit">
         </div>
   </form>
</div>

jsfiddle链接:https://jsfiddle.net/anilsarkar/txbmg2wy/3/