How to work with ui-Mask in Angularjs input

Asked

Viewed 32,691 times

8

<form name="myForm" ng-submit="addState(myForm.$valid)" novalidate >

        <input ng-model="data.cnpj" type="number" ui-mask="999.999.999-99" placeholder="CNPJ" required ng-minlength="6" ng-maxlength="12" ng-pattern="/^[0-9]{1,7}[-\.\/]?+$/">
 </form>

What to put in controller for ui-Mask to work?

I tried it but it didn’t work.

mainAppControllers.controller('Ctrl', ['myservice','$rootScope','$scope', '$routeParams', '$location','$timeout',
function(myservice, $rootScope, $scope, $routeParams, $location,$timeout ){
  • have already tried to import "ui-utils" or "ui.Mask" ?

  • Yeah, it didn’t happen :(

  • @Claudiamardegan You carried the ui-utils.js and imported the ui-utils? Any error appears in the console?

  • No error appears, I managed to make it catch, but it only works in the 1 item in the second did not create the mask. <input ng-model="data.cnpj" type="text" ui-Mask="999.999.-99" ng-Pattern="/ [0-9]{1,7}[-. /]?+ $/"> <input ng-model="data.data" type="text" ui-Mask="00/00/0000" ng-Pattern="/ [0-9]{1,7}[-./]?+$/">

  • @Andréribeiro what your Inkedin?

1 answer

6


Looking through your comment, if the first tag

<input ng-model="data.cnpj" type="text" ui-mask="999.999.999-99" ng-pattern="/^[0-9]{1,7}[-\.\/]?+$/"> 

worked, change the second to

<input ng-model="data.data" type="text" ui-mask="99/99/9999" ng-pattern="/^[0-9]{1,7}[-\.\/]?+$/">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.