What is the alternative for “ng-include” in angular2?

前端 未结 3 1853
遥遥无期
遥遥无期 2021-02-19 21:40

Is there any alternate way in angular to achieve what ng-include does in angularjs?

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 22:23

    Thinking from angular2+ way it's better to declare the child template as component:

    @Component({
      selector: 'app-child', 
      template: `
        
          here is child template that includes myTemplate
        `
    })
    export class ChildComponent {
    }
    
    
    @Component({
      selector: 'app-root',
      template: `
        

    Parent

    ` }) export class AppComponent { }

提交回复
热议问题