oninput在Angular中不起作用.选择? [英] oninput not working in Angular. Alternative?

查看:85
本文介绍了oninput在Angular中不起作用.选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个读取输入值并触发一系列true/false的函数,但是下面的代码不断返回未定义passStrength".从我发现,Angular不支持oninput.如何在Angular中实现这一目标?

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?

在我的控制器内:

$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);
    }
};

并在我的标记中:

<input id="password" oninput="passStrength()" />

推荐答案

要在输入更改时触发事件,请使用ng-change.另外,您必须定义一个ng-model.

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)" />

创建了 plunker 演示

这篇关于oninput在Angular中不起作用.选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆