Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. NGX Projection and Elements Querying
  2. ======
  3.  
  4. # Table of Contents
  5. 1. [Content projection](#content-projection)
  6. 2. [Content element querying](#content-element-quering)
  7. 2. [View element querying](#view-element-quering)
  8.  
  9. # Content projection [](#){name=content-projection}
  10.  
  11. ```typescript
  12. // article.component.ts
  13. @Component({
  14. selector: 'app-article'
  15. template: `
  16. <h1>{{title}}</h1>
  17. <ng-content></ng-content>
  18. `
  19. })
  20. export class ArticleComponent {
  21. @Input() title: string;
  22. }
  23.  
  24. // app.component.ts
  25. @Component({
  26. selector: 'app'
  27. template: `
  28. <app-article title="Article 1">
  29. <p>Article content</p>
  30. </app-article>
  31. `
  32. })
  33. export class AppComponent {}
  34. ```
  35.  
  36. ## Projection slot selectors
  37.  
  38. In addition to `ng-content` there is a `select` attribute available to specify what part of the parent content to be projected.
  39.  
  40. This is handy with multiple projection slots.
  41.  
  42. ```html
  43. <!-- article.component.html -->
  44. <h1>{{title}}</h1>
  45. <ng-content select=".article-content"></ng-content>
  46. <ng-content select=".article-footer"></ng-content>
  47. ```
  48.  
  49. ### HTML tag
  50.  
  51. ```html
  52. <!-- article.component.html -->
  53. <h1>{{title}}</h1>
  54. <ng-content select="p"></ng-content>
  55. <ng-content select="footer"></ng-content>
  56.  
  57. <!-- app.component.html -->
  58. <app-article title="Article 1">
  59. <p>Article content</p>
  60. <footer>Conclusion</footer>
  61. </app-article>
  62. ```
  63.  
  64. ### Attribute
  65.  
  66. ```html
  67. <!-- article.component.html -->
  68. <h1>{{title}}</h1>
  69. <ng-content select="[article-content]"></ng-content>
  70. <ng-content select="[article-footer]"></ng-content>
  71.  
  72. <!-- app.component.html -->
  73. <app-article title="Article 1">
  74. <p article-content>Article content</p>
  75. <p article-footer>Conclusion</p>
  76. </app-article>
  77. ```
  78.  
  79. ### CSS class
  80.  
  81. ```html
  82. <!-- article.component.html -->
  83. <h1>{{title}}</h1>
  84. <ng-content select=".article-content"></ng-content>
  85. <ng-content select=".article-footer"></ng-content>
  86.  
  87. <!-- app.component.html -->
  88. <app-article title="Article 1">
  89. <p class="article-content">Article content</p>
  90. <p class="article-footer">Conclusion</p>
  91. </app-article>
  92. ```
  93.  
  94. ### Component
  95.  
  96. # Content element querying [](#){content-element-querying}
  97.  
  98. ## Content child
  99.  
  100. ## Content children
  101.  
  102. # View element querying [](#){view-element-querying}
  103.  
  104. ## View child
  105.  
  106. ## View children
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement