【问题标题】:How to print ng-template index?如何打印 ng-template 索引?
【发布时间】:2018-05-08 19:46:32
【问题描述】:

我要打印容器的索引

我尝试写 {{index}} 但它不起作用

<ng-template #stepsClone  >
          <p>Paragraph {{index}} </p>
          <input type="button" (click)="removeStep(index)" value="X" >
        </ng-template>

export class AddInterviewComponent {

  @ViewChild('stepsClone') template;

  @ViewChild('stepsContainer', { read: ViewContainerRef }) container;

  constructor(private resolver: ComponentFactoryResolver) { }

  cloneStep() {
    this.container.createEmbeddedView(this.template);
  }
  removeStep(index: any) {
    this.container.remove(this.template[index]);
  }
}

【问题讨论】:

    标签: html angular6


    【解决方案1】:

    在你的组件内部声明

    index = 'test';
    

    请发布您的 components.ts 文件

    【讨论】:

    • 我想要容器的索引
    • 能否请您多解释一下您的要求和代码
    【解决方案2】:

    试试这个来展示你的模板:

    <ng-template [ngTemplateOutlet]="template"></ng-template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 2013-10-27
      • 1970-01-01
      相关资源
      最近更新 更多