简体   繁体   中英

how child component get parent component template in Angular4

Based on below sample

// Parent
@Component({
  selector: 'parent',
  template: `...
               <app-form-wrapper [someInput]="someInput" [otherInput]="otherInput">
                <input>
                other html ...
               /app-form-wrapper>
             ...
            `
})
export class ParentComponent {}

// Child
@Component({
  selector: 'app-form-wrapper',
  template: '<div></div>'
})
export class FormWrapperComponent {}

Is it possible for FormWrapper component to get those code/HTML wrapped by itself at parent template?

In this case, I wish my FormWrapper component able to get '< input> other HTML ...'

Please don't suggest pass in as an input.

Yes, you can using ng-content and transclusion:

// Child
@Component({
  selector: 'app-form-wrapper',
  template: '<div><ng-content></ng-content></div>'
})
export class FormWrapperComponent {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM