【发布时间】:2017-01-11 04:53:24
【问题描述】:
我仍在学习 Angular。
对于我当前的项目,我需要在我的视图中显示 HTML(例如:<h1>note1</h1><span>my first note</span><br><h1>note2</h1><span>my second note</span>)。我知道每个人都会建议使用ng-bind-html,但这不是我想要的。
我想要的是,我想检查字符串 HTML 是否有 note2 然后显示 my second note。
在控制器中,我知道如何找到字符串note2,它使用.match。
JSON
items =
[
{
"description": "<h1>note1</h1><span>my first note</span><br><h1>note2</h1><span>my second note</span>"
}
]
在控制器中找到String note2
angular.forEach(items, function(value, key) {
if (value.description.match("note2")) {
console.log(value.description);
// will output HTML <h1>note1</h1><span>my...
}
else {
console.log("string not found");
}
});
我可以做到直到找到Stringnote2,但要显示my second note我不知道。
有人可以帮我解决这个问题吗? 谢谢..
【问题讨论】:
-
你能把
items.description改成value.description吗? -
@RameshRajendran 是的,已经改了
标签: html angularjs arrays string