Why does Angular provide ng-maxlength when there is a standard maxlength?

后端 未结 2 578
终归单人心
终归单人心 2021-01-17 10:02

HTML provides a standard maxlength attribute since version 4.01. Angular provides a ng-maxlength directive.

The difference is that the standard approach doesn\'t all

2条回答
  •  余生分开走
    2021-01-17 10:30

    The previous answer may of been correct in earlier versions of angular but as of today and Angular v1.5.5, it looks like maxlength does exactly the same thing as ng-maxlength but also enforces the HTML inputs maxlength property on inputs of type text.

    Example:

    
    

    maxlength will enforce a 5 character max on the input and also add the correct angular validation class to the input.

    Whereas ngMaxlength will only enforce validation. See: https://docs.angularjs.org/api/ng/directive/ngMaxlength

    Advise: Just use maxlength.

提交回复
热议问题