Help with a global replace on a string in a directive
-
ng-change="Title1=dashboardchartType.replace('X', 'Y ');" This works for the first instance .. does anyone know how to do same as global replace or even a multiple replacement? I must be missing something cause I've tried every combination of .replace(/'X'/g, 'Y') ('/X/g', 'Y') etc. also .replace('W' | 'X', 'Y') does not evaluate.
Thanks in advance. -
Did you try
.replace(/X/g, 'Y')
? -
If you use a string as the first argument to the replace function it will only replace the first occurrence.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceI am pretty sure that a RegExp wont work in an AngularJS expression. AngularJS expressions are JavaScript like but not actually JavaScript - https://docs.angularjs.org/guide/expression
You should define a AngularJS filter or controller in a user module for something like this.
-
Yes thanks guys for the explanation and link.