【发布时间】:2015-03-13 11:32:59
【问题描述】:
在我的 AngularJS 应用程序中,我遇到了 HTML 中的字符串替换问题。
期望:
使用与部分标题和部分按钮标签相同的变量。
提交的表格(表格 (13G)、表格 (12C) 等) 附上提交的表格 计划的计划(计划(13G),计划(12C)等,) 附加计划计划 定义方案(方案 (13G)、方案 (12C) 等) 附加定义的方案 付费保险(保险 (13G)、保险 (12C) 等) 附上付费保险场景:
我有 headerText $scope 变量。它包含每个部分的LabelNames:
$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 应该是每个部分的标题,同样的LabelName 需要与文本Attach 一起用于按钮的标签文本,并且还需要删除括号之间的文本。
所以在 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 本身中实现这一点。
【问题讨论】:
标签: javascript regex angularjs