18 May 2023

Ng-Content Switch Case - Angular

                                    _             _                     _ _       _                           
  _ __   __ _        ___ ___  _ __ | |_ ___ _ __ | |_      _____      _(_) |_ ___| |__      ___ __ _ ___  ___ 
 | '_ \ / _` |_____ / __/ _ \| '_ \| __/ _ \ '_ \| __|    / __\ \ /\ / / | __/ __| '_ \    / __/ _` / __|/ _ \
 | | | | (_| |_____| (_| (_) | | | | ||  __/ | | | |_     \__ \\ V  V /| | || (__| | | |  | (_| (_| \__ \  __/
 |_| |_|\__, |      \___\___/|_| |_|\__\___|_| |_|\__|    |___/ \_/\_/ |_|\__\___|_| |_|   \___\__,_|___/\___|
        |___/
  • Directive NgxGaugeLabel
@Directive({
  selector: "ngx-gauge-label",
  exportAs: "ngxGaugeLabel"
})
export class NgxGaugeLabel {}
  • Component NgxGauge
@Component({
  selector: 'ngx-gauge'
})
export class NgxGauge {
  @ContentChild(NgxGaugeLabel) _labelChild: NgxGaugeLabel;
}
  • Component NgxGauge
<div [ngSwitch]="_labelChild != null">
  <ng-content select="ngx-gauge-label" *ngSwitchCase="true"></ng-content>
  <ng-container *ngSwitchCase="false">{{label}}</ng-container>
</div>
  • NgModule NgxGaugeModule
@NgModule({
  imports: [CommonModule],
  declarations: [
    NgxGauge,// Component
    NgxGaugeLabel // Directive
  ],
  exports: [
    NgxGaugeLabel,
  ],
})
export class NgxGaugeModule {}
  • TEST
<ngx-gauge>
    <ngx-gauge-label>
      <h1>123</h1>
    </ngx-gauge-label>
</ngx-gauge>

-- Angular 2+ --

view raw ng-content.md hosted with ❤ by GitHub

Related Posts:

  • Uncaught Error: Template parse errors is not a known element compiler.js: 2547 Uncaught Error: Template parse errors: 'app-login-box' is not a known element: 1. If 'app-login-box' is an Angular component, then verify that it is part of this module. 2. If 'app-login-box' is … Read More
  • Validate focus vào item invalid sau khi Click/Event Angular 2+npm i @ismaestro/ngx-scroll-to-first-invalid --save Github | demo Usage 1. Import the NgxScrollToFirstInvalidModule: import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core';… Read More
  • Guards Routes Angular 2+ 1. Guard Types Có bốn loại guards khác nhau chúng ta có thể sử dụng để bảo về routes của mình: CanActivate: Quyết định việc một route được kich hoạt. CanActivateChild: Quyết định việc children routes được kich hoạt … Read More
  • Deploying an Angular App to Github Pages angular-cli-ghpages Deploying an Angular App to Github Pages Installation & Setup npm i angular-cli-ghpages --save-dev Usage Usage: 1, ng build --prod --base-href "https://<user-name>.github.io/<repositor… Read More
  • Cách sử dụng @input và @output trong Angular 2+ Bước 1: Tạo project Angular 2 với cmd bấm vào đây Bước 2: Tạo component ng generate component input-output Tạo component thành công Cấu trức thư mục được tạo Component đã được tự động khai báo trong app.modul… Read More

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang