Multiple ng-content

后端 未结 4 447
庸人自扰
庸人自扰 2020-12-12 16:44

I am trying to build a custom component using multiple ng-content in Angular 6, but this is not working and I have no idea why.

This is my component code

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 17:43

    To fit the Web Component specs. Even if that's Angular. It's about avoiding attributes for selector like Angular directives or reserved attributes with another use. So, we just use the "slot" attribute. We'll see as .

    Example:

    hello-world.component.html

    
    Hello World
    
    

    app.component.html

    
      This is a 
       example.
    
    

    Result

    This is a Hello World example.
    

    Stackblitz Example

    You can use any name you want like "banana" or "fish". But "start" and "end" are a good convention to place elements before and after.

提交回复
热议问题