gpt4 book ai didi

angular - 在 Ionic 中剥离 Html 标签?

转载 作者:搜寻专家 更新时间:2023-10-30 21:23:34 24 4
gpt4 key购买 nike

我使用 ionic 3 从 wordpress api 获取了一些数据,然后在应用程序 UI 上显示相同的数据。除了内容中包含的 HTML 标记外,一切似乎都运行良好。 html 标签也被打印出来。我引用了一些建议使用以下代码的资源:-

`var app = angular.module('myHDApp', []);

app.filter('removeHTMLTags', function() {

return function(text) {

return text ? String(text).replace(/<[^>]+>/gm, '') : '';

};

});

我已经在我的 .ts 代码中实现了上述功能,但它似乎对我不起作用,因为我仍然在内容中获得 HTML 标签。

最佳答案

您发现的是 ionic v1。在 ionic 3 中,你必须先创建一个管道。

在你的命令行中,

ionic g pipe removehtmltags

您可以在 src/pipes 下找到您新创建的管道。现在在您的 removehtmltags.ts 中,

import { Pipe, PipeTransform } from '@angular/core';    

@Pipe({
name: 'removehtmltag',
})
export class RemovehtmltagPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
transform(value: string) {
if(value){
var result = value.replace(/<\/?[^>]+>/gi, ""); //removing html tag using regex pattern
return result;
}
else{}


}
}

您现在可以像这样在您的 html 文件中使用此管道,

<p>{{yourData | removehtmltag}}</p>

关于angular - 在 Ionic 中剥离 Html 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44896519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com