JQuery and Angular interact poorly
Chocolate and peanut butter go great, but AngularJS and jQuery are a painful mix. We all tried (with varying success) to accomplish this.
The problem is that the jQuery DOM manipulation works outside of the AngularJS digest loop . The lesson usually is that it is better to use pure Angular.
Alternative # 1: Angular UI
Try Angular -UI . A set of tools, each of which the Angular developer can use.
Any mask you want to implement can be done using the ui-mask directive:
Want a date mask?
<input type="text" ng-model="date" ui-mask="99/99/9999" />
Currency mask?
<input type="text" ng-model="currency" ui-mask="$99999999.99" />
Phone mask?
<input type="text" ng-model="phone" ui-mask="1 (999) 999-9999" />
:
:
Alternative # 2: Filters
Angular has built-in filters:
Currency:
$filter('currency')(amount, symbol)
Date:
$filter('date')(date, format)
Insist on using jQuery? Try the jQuery Passthrough directive from the Angular -ui suite . I have not used this directive, but this is an intriguing option:
To call something like $ .fn.tooltip (), just do ui-jq = "tooltip". Note that the function name must be identical. It also works with regular jQuery commands, such as $ .fn.slideUp ().
The ui-options attribute is used to pass parameters. The value will be evaluated in the context of $ scope and passed to the function. If default values ββare set, the passed parameters will expand them. If a string, the default parameters will be ignored.
Use the jq directive name to place the names inside uiJqConfig. then the subspace parameters for each function by the name of that function (just like ui-jq passes it), so you donβt have to go through every time you call the directive.