首页 > 解决方案 > 有没有办法将输入字符串中的锚标记传递给标签

问题描述

我有一个用于复选框的自定义类,其中标签和输入与类一起定义。

我在另一个类中使用该组件,我需要传递一个包含链接的标签,例如:请接受继续。那么是否可以使用包含链接的上述字符串传递标签?

customCheckbox.component.ts

<div class="form-group" [formGroup]="checkboxForm">
  <label class="checkboxContainer">
    {{ label }} <input id="{{ id }}" type="checkbox" 
 [formControlName]="checkboxFormName" />
    <span class="checkmark"></span>
  </label>
</div>

用法

<custom-checkbox
          id="_id"
          [checkboxForm]="checkboxForm"
          [nameOfControl]="checkboxFormName "
          label="{'Please accept the <a>terms and condition </a> .'" >
        </custom-checkbox>

所以需要这种类型的标签。

标签: angularinputangular7

解决方案


您可以将标签的文本传递到标签的 innerHTML 中。像这样:

  label = 'This is normal,but <a href="https://www.google.com"> this is link</a>'

<label [innerHTML]="label"></label>

推荐阅读