13 November 2018

:CSS pseudo-class host ::ng-deep :host-context() /deep/ >>> Styling in Angular 2+

:host ::ng-deep
Thứ tự các component lồng nhau theo mũi tên xuống
::ng-deep


/* Đặt ở bất kỳ component đều có màu đỏ */
/* Toàn bộ thẻ p ở các component có màu đỏ - nó mang tính tổng thể */
::ng-deep p { color: red; }

Hiển thị:
Start editing to see some magic happen :)
person works!
company works!
address works!

:host ::ng-deep

/* Đặt ở company.component.scss - child(2) */
/* Toàn bộ thẻ p ở company.component và address.component có màu xanh */
:host ::ng-deep p {
    color: blue; 
} 

Hiển thị:
Start editing to see some magic happen :)
person works!
company works!
address works!

:host

/* Đặt ở company.component.scss - child(2) */
/* Thẻ p chỉ có company.component có màu xanh - mang tính chất áp dụng cho chính bản thân company.component */
:host p {
    color: blue; 
} 

Hiển thị:
Start editing to see some magic happen :)
person works!
company works!
address works!



:host-context()
:host-context()

/* Đặt ở themeable-button.component.scss - child */
/* Phụ thuộc component cha sẽ dùng class-theme nào - hiện tại nó đang dùng .red-theme */
:host-context(.blue-theme) .btn-theme {
  background: blue;
}
:host-context(.red-theme) .btn-theme {
  background: red;
}



/deep/ and >>>
Cả hai đều không nên sử dụng :: ng-deep

Tìm hiểu thêm CSS pseudo-class tại here
Hy vọng điều này đã giúp bạn

Related Posts:

  • Angular Runtime compilation - Dynamic Template From HTTP Call Biên Dịch Thời Gian Thực Angular  Template Động gọi HTTP hoặc mẫu HTML có sẵn. MyComponent 2020 import { Component, OnInit } from '@angular/core'; import { HttpClientModule } from '@angular/commo… Read More
  • Angular Google Map with AgmMap - Icon MakerStackblitzhttps://stackblitz.com/edit/angular-google-maps-agm-map<agm-map>https://angular-maps.com/api-docs/agm-core/components/agmmap#source<agm-marker>https://angular-maps.com/api-docs/agm-core/directives/agmmar… Read More
  • Custom Modal mở bằng Service Angular 2+Use2020import { Component, OnInit, } from '@angular/core'; import { ApiService } from '../../shared/services/api.service'; import { PushMessageService } from '../../shared/services/push-message.service'; @Component({ s… Read More
  • Renderer2 in Angularimport {Injectable, Renderer2, RendererFactory2} from '@angular/core'; @Component({ selector: 'app-example', templateUrl: './example.component.html', styleUrls: ['./example.component.scss'], }) export class ExampleComp… Read More
  • Validation formGroup multiple patterns trong Angular 2Validation FormGroup Multi PatternsTạo project Angular bấm vào đây app.component.html<input formControlName="name" class="form-control" type="text" [ngClass]="{ 'is-valid': (f?.name.valid && (f?.name.t… Read More

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang