AngularJs:替换字符串的一部分 [英] AngularJs: Replace a part of a string
本文介绍了AngularJs:替换字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
AngularJs中是否有替换字符串的方法?
Is there a way in AngularJs to replace a string?
我正在尝试做类似的事情:
I'm trying to do something like:
{{string.replace('some', 'thing')}}
谢谢!
推荐答案
您的代码段有效!
演示: 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';
}
);
输出为this is thing
演示: http://plnkr.co/edit/yNuNeE5yO3rgKAYfGx48?p=preview
这篇关于AngularJs:替换字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文