Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is ng-content? #36

Open
Shashidharknaik opened this issue Dec 26, 2021 · 2 comments
Open

What is ng-content? #36

Shashidharknaik opened this issue Dec 26, 2021 · 2 comments

Comments

@Shashidharknaik
Copy link

Please add question & answer about ng-content.

@sudheerj
Copy link
Owner

@Shashidharknaik Can you create PR?

@saheel-ahmed
Copy link

Example:

my-button.component.ts

import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'my-button',
  template: `
    <button class='action-btn' (click)="action()">
      <ng-content></ng-content>
    </button>
  `
})

export class MyButtonComponent implements OnInit {
  constructor() { }
  ngOnInit() {
  }
  action(){
    console.log("action triggered")
  }
}

app.component.html

<my-button>
  Button 1
</my-button>

<my-button>
  Button 2
</my-button>

allows you to add dynamic content inside a custom component.

Using , we can create the same with different labels.

helps us achieve transclusion in Angular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants