This is my custom Currency Mask for Angular JS Directive.

So when I was using Angular JS, I wanted to set the form in a modal dialog window back to its pristine state whenever it was shown.

Problem was, the form is always undefined. If I place a code within the modal window, the form exists but when I call it in a Javascript function, it is undefined.

The solution is to add $parent to your form name like this:

This will automatically create the form object in your parent controller. Then, you can simply access it using the scope like $scope.myForm.

Here is my custom Angular JS Directive to ensure user input is within the valid number range. The code works like this:

  • The user input is parsed by a regex expression to ensure that only digits are allowed.
  • Once it gets parsed, it will check if the value is within the number range specified using range-min and range-max attributes.
  • If it is below the range minimum, set the ngModel value to the range minimum value.
  • If it is more than the range maximum, set the ngModel value to the range maximum value.

Here is the Javascript code for the directive.

And here is the sample HTML code.

A good case scenario to apply this directive is for input fields for percentage where 1-100 is your number range.

Related Posts Plugin for WordPress, Blogger...