Angularjs Form/Field validation using JavaScript function without directives

前端 未结 4 1552
你的背包
你的背包 2020-12-14 12:54

Is there a way to validate a field in angular without using a directive? For example: I want to make following validation on an input field.

4条回答
  •  抹茶落季
    2020-12-14 13:09

    Well you can try to create a func

    Value must be an even number
    
    $scope.isEven=function(data) {
        if(data) {
            return data%2===0
        }
        return true;
    }
    

    The method can either be defined on the current controller scope or on $rootScope.

    Not a very angular way, as directives would be better but i think it would work.

提交回复
热议问题