AngularJS 'controller as' and form.$valid

眉间皱痕 提交于 2019-12-05 05:24:57

You could do as @ons-jjss suggested but if you prefer not to inject $scope into you controller, then just change your form name as

<form name="main.contactForm" novalidate>

and it'll work like a charm.

You need to use in this way: $scope.contactForm.$valid

EDIT

To work the above syntax, $scope needs to be inhjected in controller.

app.controller('MainController', function($scope) { 
  //code 
} 

You need to use main.contactForm in form name attribute then it's solved. See this

`http://plnkr.co/edit/us8MKU3LZ7pnLV66xIrv?p=preview`

You can pass your form as a parameter to function submit as ng-click="main.submit(contactForm)

and then validate it in controller method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!