如何将加载AJAX的表单绑定到' ngModel' [关]

时间:2014-09-09 01:08:40

标签: ajax angularjs angularjs-directive angularjs-scope

收到http://examle.com/ajax/login.html

<form method="post" action="/login.html" name="formLogin" data-ng-model="formLogin" data-ng-submit="submitLogin($event)" novalidate="novalidate" >
   <input type="hidden" csrf="csrf" data-ng-model="formLogin.csrf" value="" name="LoginForm[csrf]">

   <input type="text" data-ng-minlength="2" data-ng-required data-ng-model="formLogin.email" placeholder="e-mail" autofocus="autofocus" name="LoginForm[email]"></div>
   <span class="error" ng-show="formLogin['LoginForm[email]'].$error.required">Required!</span>

   <input type="text" data-ng-minlength="2" data-ng-required data-ng-model="formLogin.password" placeholder="password" autofocus="autofocus" name="LoginForm[password]"></div>
   <span class="error" ng-show="formLogin['LoginForm[password]'].$error.required">Required!</span>

   <button ng-disabled="formLogin.submitted" name="login-button" class="btn btn-primary" type="submit">OK</button>
</form>

指令代码如下所示:

app.directive('formLogin', function(){
   return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModelCtrl) {
          var inputs = element[0].querySelectorAll('input');
      }
   };
});

在经典example中,如果指定表单的名称,表单控制器将以此名称发布到相关范围中。是否有可能为AJAX加载的表单,如? 问题出在加载表格后的验证输入中。

0 个答案:

没有答案