if statement in angularjs is not working -


i have login page evaluates username , password using angularjs seems conditional statement in controller returns false if put true value

here's html file

<div class="row"> <form action="/">      <input type="text" class="form-control" id="username" ng-model="username" required>                          <input type="password" class="form-control" id="username" ng-model="password" required>                          <br>     <button type="button" style="width: 40%;"  ng-click="submit()"> log in </button>  </form>      </div> 

and controller

var app = angular.module('myapp', ["ngroute"]);  app.controller('ctrl',  function($scope, $location) {       $scope.submit = function() {         var username = $scope.username;         var password = $scope.password;          if($scope.username == 'admin' && $scope.password == 'admin') {             console.debug('success');         } else {             console.debug('fail');         }     }   }); 

every time input 'admin' in username , password 'fail' in console means submit function returns false . .

1) per html spec need cannot have same id on 2 different elements html 4.1

2)you should explicitly declare objects want control have injected below. way when minifiy code, dependency injection continue work

app.controller('ctrl',['$scope','$location'  function($scope, $location) { }]); 

3) answer question why isnt working. plunkr works. removed routing, because wasnt needed. make sure typing in 'admin' no spaces/caps


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -