Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJs: Replace a part of a string

Tags:

angularjs

Is there a way in AngularJs to replace a string?

I'm trying to do something like:

{{string.replace('some', 'thing')}}

Thanks!

like image 896
Rocky Yost Avatar asked Nov 30 '14 22:11

Rocky Yost


People also ask

How to replace a character in a string in AngularJS?

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);

How do you replace a section of a string in TypeScript?

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.

How do I change a value in TypeScript?

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]);


1 Answers

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

enter image description here

demo: http://plnkr.co/edit/yNuNeE5yO3rgKAYfGx48?p=preview

like image 196
Jossef Harush Kadouri Avatar answered Sep 29 '22 17:09

Jossef Harush Kadouri