pattern based replace of string in angularjs -
i trying replace based on pattern , getting error.
{{n.tostring().replace(/\b(?=(\d{3})+(?!\d))/g, ",")}}   n number.
error: [$parse:lexerr] lexer error: unexpected next character @ columns 36-36 [] in expression
angular's having hard time regex being inline in template, put replace statement helper function on scope:
$scope.convert = function(val) {   return val.tostring().replace(/\b(?=(\d{3})+(?!\d))/g, ","); }   then in template call function:
{{ convert(n) }}    another option create custom filter:
app.filter('convert', function() {   return function(input) {     return input.tostring().replace(/\b(?=(\d{3})+(?!\d))/g, ",");     }; });   then pipe value filter:
{{ n | convert }}       
Comments
Post a Comment