相关疑难解决方法(0)

Angular HTML绑定

我正在写一个Angular应用程序,{{myVal}}我想要显示一个响应.

我怎么做?如果我只是使用绑定语法,innerHTML它会编码所有div字符(当然).

我需要以某种方式将a的内部html绑定{{myVal}}到变量值.

angular2-template angular2-databinding angular

756
推荐指数
11
解决办法
46万
查看次数

在typeScript angular 2中解码html

我从后端得到一个编码html但我无法解码它.

我尝试使用decodeURIComponent和decodeURI.

I got from server='
"<table style="background-color: white;">
    <tbody>
        <tr>
            <td>
                    <div id="voucher">
                        <table>
                            <tr>
                                <td colspan="1" class="normal-left">ID:</td>
                                <td colspan="3" class="normal-left">ce203c7c804c4f258947adf3d63b2d7d</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </td>
        </tr>
    </tbody>
</table>"
' 
Run Code Online (Sandbox Code Playgroud)

// This is my HTML

<ion-content padding>
<ion-list>
  <ion-item>
    <span [innerHtml]="aux"></span>
  </ion-item>
  </ion-list>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

这就是结果

我曾经在jquery中用document.getElementById("aux")解码.innerHTML = $('').html(voucher).text();

但我不知道Angular 2是否有类似的东西.

谢谢

html ionic2 angular

5
推荐指数
1
解决办法
6334
查看次数

ngFor 中的渲染组件

我正在循环对象数组并在对象内部指定要加载的组件。例如,循环中的一项是

{
  label: 'Patient\'s Weight',
  subtitle: '',
  component: WeightComponent,
},
Run Code Online (Sandbox Code Playgroud)

在循环中我想渲染WeightComponent,但它只是渲染function WeightComponent()为文本。

我知道我这样做是错误的,但我不确定正确的方法是什么。我也尝试过

{
  label: 'Patient\'s Weight',
  subtitle: '',
  component: '<app-weight></app-weight>',
},
Run Code Online (Sandbox Code Playgroud)

但这也只是呈现为文本。我需要使用渲染服务类型吗?我看到了使用[innerHTML] How to translate HTML string to real HTML element by ng-for in Angular 2? 的建议。但他们说这条路线容易受到攻击。

目前正在这样做,这不太理想

<div *ngFor="let step of selectedDosing.steps; index as i" class="step" [attr.step]="i">
  <ion-label class="step-title">
    <span class="number">{{ i + 1 }}</span>
    <span class="labels">
      <div class="main-label">{{ step.label }}</div>
      <div class="subtitle">{{ step.subtitle }}</div>
    </span>
  </ion-label>
  <app-hepatic-impairment *ngIf="step.component == 'hepatic-impairment'"></app-hepatic-impairment>
  <app-recommended …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
2595
查看次数