Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oninput not working in Angular. Alternative?

Im trying to create a function that reads the value of an input and triggers a series of true/false, however the code below keeps returning "passStrength is not defined." From what I can find, oninput isn't supported by Angular. How can achieve this in Angular?

Within my controller:

$scope.passStrength = function(input) {
    if (input.value.toLowerCase().indexOf(/[a-z]/) > -1) {
        $scope.lwrChar = true;
        console.log('lower ' + $scope.lwrChar);
    } else if (input.value.toUpperCase().indexOf(/[A-Z]/) > -1) {
        $scope.uprChar = true;
        console.log('upper ' + $scope.uprChar);
    } else if (input.value.indexOf() == !isNaN(n)) {
        $scope.nbrChar = true;
        console.log('number ' + $scope.nbrChar);
    } else if (input.value.length >= 8) {
        $scope.countChar = true;
        console.log('count ' + $scope.countChar);
    }
};

and in my markup:

<input id="password" oninput="passStrength()" />
like image 923
Christian Hill Avatar asked Apr 08 '16 20:04

Christian Hill


1 Answers

To fire an event when the input changes, use ng-change. Also, you must define a ng-model.

<input ng-model="password" ng-change="passStrength(password)" />

Edit: Created a plunker demonstrating it

like image 59
tpsilva Avatar answered Sep 21 '22 12:09

tpsilva