在我的AngularJS
应用程序中,我遇到了HTML中的字符串替换问题。AngularJS字符串替换为HTML
期望:
使用相同的变量作为区段标题和部分按钮的标签的。
Submitted Forms (Form (13G), Form (12C) and etc.,) Attach Submitted Forms Planned Plans (Plan (13G), Plan (12C) and etc.,) Attach Planned Plans Defined Schemes (Scheme (13G), Scheme (12C) and etc.,) Attach Defined Schemes Paid Insurances (Insurance (13G), Insurance (12C) and etc.,) Attach Paid Insurances
场景:
我HEADERTEXT $scope
变量。它包含LabelName
s各自节:
$scope.headerText = [{
LabelName: 'Submitted Forms (Form (13G), Form (12C) and etc.,)'
}, {
LabelName: 'Planned Plans (Plan (16K), Plan (12C) and etc.,)'
}, {
LabelName: 'Defined Schemes (Scheme (11H), Scheme (12C) and etc.,)'
}, {
LabelName: 'Paid Insurances (Insurance (10G), Insurance (12C) and etc.,)'
}];
这LabelName
应该是用于与文本Attach
沿按钮的标签文字标题每一部分和相同LabelName
需求,同时还需要删除文本在括号之间。
所以在HTML文件中,我尝试下面的代码来实现结果:
<div ng-repeat="header in headerText">
<span ng-bind="header.LabelName"></span>
<br />
<button>{{addText.replace("{0}", header.LabelName).replace(/(\(.*\))/g, '')}}</button>
<hr />
</div>
的意思,我想用空白空间
(表格(13G)一起替换括号中的内容,表格(12C)等,)
从
呈交的表格(表格(13G),表(12C)等,)
并使用该按钮的标签文本。
我试过正则表达式.replace(/(\(.*\))/g, '')
,但它不支持。
有没有什么办法可以在HTML
本身实现这个。
我实际的期望是实现HTML本身的'正则表达式”,这就是希望不可能在html.This做的是很好.. – Arulkumar 2015-03-13 13:07:50
@Arulkumar为Javascript代码很复杂,最好在控制器中创建一个方法并从视图中调用它。 – anpsmn 2015-03-13 13:16:38
是的,我了解复杂性。此修补程序很有帮助。 – Arulkumar 2015-03-13 13:23:33