Thursday, 18 May 2017

MEAN Stack javascript condition comparing user input and data from db

I'm trying to make a condition where if user's input is the same, then it will certain function, if not it will run another function. Just like this:

do {
  for (var i = 0; i < products.userinfo.length; i++) {
    if (products.userinfo[i].username.toUpperCase() == $scope.user.username.toUpperCase()) {
      console.log("Same username ==> ", products.userinfo[i].username.toUpperCase());
      $scope.usernameError();
      i += 1;
    }
    i += 1;
  }
} while (i < 1) {
  for (var i = 0; i < products.userinfo.length; i++) {
      console.log("db ==> ", products.userinfo[i].username.toUpperCase());
      console.log("input ==> ", $scope.user.username.toUpperCase());
  }
console.log("Proceed registering!");
  //$scope.autoregister();
  i += 1;
}

The problem is it keep get into the second condition. It suppose to enter the first condition because the last array is equal to the user input. One more thing, why do I always get 304 at my terminal?

.state('register', {
                url: '/register',
                templateUrl: '/register.html',
                controller: 'AuthCtrl',
                resolve: {
                    displayPromise: [
                        'products',
                        function(products) {
                            //return products.getAccountForRegistration();
                            return products.getAccount();
                        }
                    ]
                },
                onEnter: ['$state', 'auth', function($state, auth) {
                    if (auth.isLoggedIn()) {
                        $state.go('main');
                    }
                }]
            })
o.getAccount = function() {
            return $http.get('http://localhost:3000/getaccounts').success(function(data) {
            angular.copy(data, o.userinfo);
            });
            console.log(o.userinfo);
            };

Where did I do wrong?



via Azinuddin AleleCha

No comments:

Post a Comment