javascript - im getting error. angular.js:13550 TypeError: Cannot read property '$invalid' of undefined -


i'm trying copy code: http://blog.mgechev.com/2014/02/08/remote-desktop-vnc-client-with-angularjs-and-yeoman/ getting error (see error down below).

can me?

here js code:

'use strict';  angular.module('clientapp')   .controller('mainctrl',   function ($scope, $location, vncclient) {      $scope.host = {};     $scope.host.proxyurl = $location.protocol() + '://' + $location.host() + ':' + $location.port();      $scope.login = function () {       var form = $scope['vnc-form'];       if (form.$invalid) {         form.$setdirty();       } else {         vncclient.connect($scope.host)         .then(function () {           $location.path('/vnc')         }, function () {           $scope.errormessage = 'connection timeout. please, try again.';         });       }     };    }); 

and html code:

<div class="container">    <div class="row" style="margin-top:20px">       <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3" ng-controller="mainctrl">       <form role="form" name="vnc-form" novalidate class="css-form">         <fieldset>           <h2>vnc login</h2>           <hr class="colorgraph">           <div class="form-error" ng-bind="errormessage"></div>           <div class="form-group">               <input type="text" name="hostname" id="hostname-input" class="form-control input-lg" placeholder="hostname" ng-model="host.hostname" required ng-minlength="3">           </div>           <div class="form-group">               <input type="number" min="1" max="65535" name="port" id="port-input" class="form-control input-lg" placeholder="port" ng-model="host.port" required>           </div>           <div class="form-group">               <input type="password" name="password" id="password-input" class="form-control input-lg" placeholder="password" ng-model="host.password">           </div>           <div class="form-group">               <a href="" class="btn btn-lg btn-primary btn-block" ng-click="login()">login</a>           </div>           <hr class="colorgraph">         </fieldset>       </form>     </div>   </div>  </div> 

and error:

angular.js:13550 typeerror: cannot read property '$invalid' of undefined     @ scope.$scope.login (main.js:12)     @ fn (eval @ <anonymous> (angular.js:14432), <anonymous>:4:206)     @ expensivecheckfn (angular.js:15485)     @ callback (angular.js:25018)     @ scope.$eval (angular.js:17229)     @ scope.$apply (angular.js:17329)     @ htmlanchorelement.<anonymous> (angular.js:25023)     @ htmlanchorelement.jquery.event.dispatch (jquery.js:4737)     @ htmlanchorelement.elemdata.handle (jquery.js:4549) 

form name should not having "-" in between if have access in angular controller. rename form name 'vncform" , done.

example:

<form role="form" name="vncform" novalidate class="css-form"> </form>  $scope.login = function () {                           var form = $scope['vncfrom'];                           if (form.$invalid) {                             form.$setdirty();                           }                           ...                         }; 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -