• Geek Answers Handbook

    Passing HTML to my component

    Consider the following sidebar.component.html component:

     <div class="sidebar"> <ul> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Go to the dashboard"> <a href="#"> <i class="material-icons">home</i> <span>Home</span> </a> </li> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Manage your times"> <a href="#"> <i class="material-icons">watch_later</i> <span>Times</span> </a> </li> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Go to settings"> <a href="#"> <i class="material-icons">settings</i> </a> </li> </ul> </div> 

    In app.component.html I use the sidebar using its tags ( <sidebar> ). However, now I want to make the <li> elements <sidebar> inside the <sidebar> tags so that they are no longer inside the sidebar.component.html to make the component reusable.

    I'm not sure what it's called, and it's hard for me to find it.

    Thanks in advance.

    +7
    html angular angular-components
    Limnic Feb 16 '17 at 12:09
    source share
    1 answer

    Create a sidebar component with <ng-content> where past children should be displayed

     @Component({ selector: 'sidebar', template: '<ul><ng-content></ng-content></ul>' }) export class SidebarComponent { } 

    and use it like

     <sidebar> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Go to the dashboard"> <a href="#"> <i class="material-icons">home</i> <span>Home</span> </a> </li> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Manage your times"> <a href="#"> <i class="material-icons">watch_later</i> <span>Times</span> </a> </li> <li class="tooltipped" data-position="right" data-delay="50" data-tooltip="Go to settings"> <a href="#"> <i class="material-icons">settings</i> </a> </li> </sidebar> 
    +10
    Günter zöchbauer Feb 16 '17 at 12:23
    source share

    More articles:

    • Migrating AWS EC2 to Azure VM using nodsjs code - node.js
    • Does C ++ provide normal parameters after variational pattern parameters? - c ++
    • Google Analytics SDK 10.2.0 has StrictMode violations - google-analytics-sdk
    • Kotlin: safe lambda (no memory leak)? - android
    • Swift3: empty fetch when accessing master data from Watch Extension through AppGroups - ios
    • How to edit user privileges using JetBrains Datagrip? - mysql
    • Cannot use forEach and lambda in android min sdk version less than 24 - android
    • Uncaught ReferenceError: show value not defined (mobile only) - javascript
    • How to make simple if statements inside a declarative pipeline in Jenkins - jenkins
    • Assigning variables in a parallel step using declarative pipeline steps in Jenkins - jenkins

    All Articles

    Geek Answers | 2019