相关疑难解决方法(0)

angular 4+为ngComponentOutlet动态创建的组件分配@Input

在Angular 4中动态创建一个组件,你可以使用ngComponentOutlet指令:https://angular.io/docs/ts/latest/api/common/index/NgComponentOutlet-directive.html

这样的事情:

动态组件

@Component({
  selector: 'dynamic-component',
  template: `
     Dynamic component
  `
})
export class DynamicComponent {
  @Input() info: any;
}
Run Code Online (Sandbox Code Playgroud)

应用

@Component({
  selector: 'my-app',
  template: `
     App<br>
     <ng-container *ngComponentOutlet="component"></ng-container>
  `
})
export class AppComponent {
  this.component=DynamicComponent;
}
Run Code Online (Sandbox Code Playgroud)

如何传递@Input() info: any;此模板中的信息<ng-container *ngComponentOutlet="component"></ng-container>

javascript typescript angular

18
推荐指数
3
解决办法
1万
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1