Thuta Learning
ရှာဖွေရန်
AdvancedWeb Developmentintermediate

Content Projection (ng-content)

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Content Projection (ng-content) သည် parent component မှ content ကို child component ထဲသို့ pass လုပ်ရန် အသုံးပြုသည်။

typescript
// card.component.ts
@Component({
  selector: 'app-card',
  template: `
    <div class="card">
      <div class="card-header">
        <ng-content select="[header]"></ng-content>
      </div>
      <div class="card-body">
        <ng-content></ng-content>
      </div>
      <div class="card-footer">
        <ng-content select="[footer]"></ng-content>
      </div>
    </div>
  `
})
export class CardComponent { }

// Usage in parent
<app-card>
  <h2 header>Card Title</h2>
  <p>This is the main content of the card.</p>
  <button footer>Action</button>
</app-card>
You should see
(Parent မှ pass လုပ်လိုက်သော content များသည် card component ၏ designated slots များတွင် ပေါ်လာမည်)
Content Projection (ng-content) | Thuta Learning