Can't get ngTemplateOutlet to work

前端 未结 3 2005
我寻月下人不归
我寻月下人不归 2020-12-03 07:06

I am trying to build a listing component in Angular2 that takes the items, the columns and the templates for the fields of the items from the user of the component. So I am

3条回答
  •  爱一瞬间的悲伤
    2020-12-03 07:43

    you can do it without ngOutletContext. You have to use ng-template instead of template. following code works for me:

    app.component.html:

    app-parent is a child of app-component. app-child is declared in app-component as template and this template is used in app-parent.

    app.parent.html:

    app.parent.ts:

    @Component({
      selector: 'app-parent',
      templateUrl: './parent.component.html',
      styleUrls: ['./parent.component.css']
    })
    export class ParentComponent implements OnInit {
    
      @Input() public templateChild1: TemplateRef;
    
      public ngOnInit() {
      }
    
    }
    

提交回复
热议问题