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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -