简体   繁体   中英

Checking login and password in AngularJS

When I press Sign In in my autorization it should change the signInValid to true ,but unfortunetly only alert working:(

And is it correct to use FOR in angularJS to see is login and pass correct? Or there are some better ways to do it?

Here`s my JS code:

  $scope.signInValid = false;
   $scope.signIn = function (userDetails) {
    for (let i = 0; i < $scope.userlist.length; i++) {
        if (userDetails.login == $scope.userlist[i].username && userDetails.password == $scope.userlist[i].password) {
            alert('welcome')
            $scope.signInValid = true;
        }
    }
}

Here`s HTML code:

  <h1>Permissions allowed: <span style="{{setStyle(signInValid)}}">{{signInValid}}</span></h1>

And if you invert and set the signInValid property to true first ?

if (userDetails.login == $scope.userlist[i].username && userDetails.password == $scope.userlist[i].password) {
      $scope.signInValid = true;
      alert('welcome');
    }

通过将控制器设置为body block来修复它,我的div不在控制范围内。感谢大家的回答!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM