angularjs - Angular - Cannot read property '$invalid' of undefined -
i creating login page using angular , typescript. when submit button clicked, login
function in controller fire, if form invalid returns.
this first time using typescript, every time try put in if statement check if form invalid throws error cannot read property '$invalid' of undefined
.
here html:
<form class="login-form" name="loginform" ng-submit="vm.login()" novalidate> <input type="email" name="email" placeholder="email" required ng-model="vm.email" ng-class="{true: 'input-error'}[submitted && loginform.email.$invalid]"/> <input type="password" name="password" placeholder="password" required ng-model="vm.password" ng-class="{true: 'input-error'}[submitted && loginform.password.$invalid]"/> <input type="submit" id="submit" ng-click="submitted=true"/> </form>
and here compiled javascript:
var loginmodule; (function (loginmodule) { var logincontroller = (function () { function logincontroller() { } logincontroller.prototype.login = function () { if(this.loginform.$invalid) { return; } console.log("login clicked, email " + this.email + " , password " + this.password); }; return logincontroller; })(); loginmodule.logincontroller = logincontroller; })(loginmodule || (loginmodule = {})); angular.module('loginmodule', []).controller('logincontroller', loginmodule.logincontroller);
it looks common issue people not specifying form name, not case here. know why getting error?
you need controller alias in form name
<form name="vm.loginform" ng-submit="vm.login()" novalidate>
Comments
Post a Comment