angular2 ng-template in a separate file

前端 未结 5 941
孤城傲影
孤城傲影 2021-02-19 09:05

angular2 how to use ng-template from a different file? When I place the ng-template within the same HTML where I use it works but when I move ng-template into a separate file th

5条回答
  •  一整个雨季
    2021-02-19 09:47

    You can use something like this (template is used from another component):

    @Component(
        template: ''
    )
    export class MessageTemplate {
        infoMessage: InfoMessage;    
    }
    
    @Component(
        ....
    )
    export class InfoMessage{    
        @ContentChild('columnTemplate') template: TemplateRef;
    
        constructor(private messageTemplate: MessageTemplate) {
            messageTemplate.infoMessage = this;
        }
    }
    

提交回复
热议问题