【问题标题】:Dynamic inject angular component into parent component将角度组件动态注入父组件
【发布时间】:2017-07-10 10:34:09
【问题描述】:

我正在尝试将 Angular 组件注入到父组件中,使用 [innerHTML] 属性,我只获取 HTML 代码,它不会编译到我的子组件中

我的子组件:

@Component({
  selector: 'text-step',
  styleUrls: ['./text.scss'],
  templateUrl: 'text.html',
})

export class TextStepComponent implements OnInit {

  @Input() step: object;

  constructor(
  ) { }

  ngOnInit() {
  }

}

我的父组件:

renderSteps(listSteps) {
  var context = this;
  var result = '';
  listSteps.forEach(function(step) {

    switch (step.type) {
      case 'form_text':
        context.innerHtml += '<text-step [step]=\"' + step + '\"></text-step>';
        break;
    }
  });
}

这意味着每一步都会将 text-step 组件附加到 div

我该怎么做?

【问题讨论】:

标签: angular


【解决方案1】:

你必须使用。 ComponentFactoryResolver

请看工作demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-18
    • 2021-01-27
    • 1970-01-01
    • 2020-01-06
    • 2019-02-08
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    相关资源
    最近更新 更多