Is there a way in AngularJs to replace a string?
I'm trying to do something like:
{{string.replace('some', 'thing')}}
Thanks!
The replace() method can be used to search the particular character(s), which is getting replaced with a specific character(s) & return a new generated string. Syntax: string. replace(char findChar, char replacedChar);
The replace() method can be used in a TypeScript string to replace a particular substring or a match (regular expression) in a string. All we need to do is pass the substring or regular expression of the substring we want to replace.
The replace() is an inbuilt function in TypeScript which is used to find a match between a regular expression and a string, and replaces the matched substring with a new substring. Syntax: string. replace(regexp/substr, newSubStr/function[, flags]);
your snippet works!
demo: http://plnkr.co/edit/yNuNeE5yO3rgKAYfGx48?p=preview
html
<body ng-app="app">
<div>
<div class="container" ng-controller="mainCtrl">
<p>
{{ name.replace('some', 'thing') }}
</p>
</div>
</div>
</body>
js
var app = angular.module('app', []);
app.controller('mainCtrl',function($scope) {
$scope.name = 'this is some';
}
);
the output is this is thing
demo: http://plnkr.co/edit/yNuNeE5yO3rgKAYfGx48?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With