我正在處理一個 angular 專案,我在 api 的回應中得到一個鏈接,如下所示,我正在 html 中對其進行迭代。
<a class="test" href="https://www.google.com/" target="_blank">click here</a>
我想在我的輸出中將我收到的 href 顯示為超鏈接,它應該導航到適當的鏈接。截至目前,它在輸出中顯示為純文本。請幫我實作這個功能。
我已經在 stackblitz 中更新了我的代碼。作業堆疊閃電戰:
https://stackblitz.com/edit/angular-ivy-qxfftw?file=src/app/app.component.ts
來自 api 的回應:
apiresponse: any = {
message: 'message',
response: [
{
hrefmessages:
'i need this link to be shown as hyperlink <a href="https://www.google.com/" target="_blank">click here</a>. ',
icons: [
{
icon1: 'hello',
name: 'hello',
age: 'hello',
},
],
},
{
hrefmessages: 'This is also a href test message',
icons: [
{
icon1: 'test',
name: 'test',
age: 'test',
},
],
},
],
};
uj5u.com熱心網友回復:
您需要設定要將回應中的 HTML 系結到的標記的內部 HTML。例子:
<div [innerHTML]="response[0].hrefmessages"></div>
StackBlitz:https ://stackblitz.com/edit/angular-ivy-8ydusb ? file = src/app/app.component.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/327206.html
