AngularJS 'controller as' and form.$valid

All we need is an easy explanation of the problem, so here it is.

I want to check if a form is valid inside an angular controller. This seems straightforward when using $scope, but I can’t get it to work with the ‘controller as’ syntax.

When I attempt to access form.$valid I get the error message “Cannot read property ‘$valid’ of undefined”.



<div ng-app="demoControllerAs" ng-controller="MainController as main">
  <form name="contactForm" novalidate>
      <input type="email" name="email" ng-model="" required />
      <textarea name="message" ng-model="main.message" required></textarea>
    <input type="submit" value="submit" ng-click="main.submit()" />


var app = angular.module('demoControllerAs', []);

app.controller('MainController', [function () {
    var main = this;

    main.submit = function () {
        var isValid = main.contactForm.$valid;

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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.

Method 2

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


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

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

Method 3

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


Method 4

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

and then validate it in controller method

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply