Reputation: 150
Is there a way in AngularJs to replace a string?
I'm trying to do something like:
{{string.replace('some', 'thing')}}
Thanks!
Upvotes: 5
Views: 27611
Reputation: 34207
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
Upvotes: 12
Reputation: 33141
Why don't you just replace part of the string inside your controller?
So in your view you have: {{myString}}
and in your controller you have: $scope.myString.replace('some', 'thing');
Upvotes: 2