Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

html - changing the style of a component which is being used by its selctor

I am using a component with its selector in another component, like this:

<div class="col-xl-4" style="margin-bottom: 30px;">
    <app-patient-info-accordion *ngIf="patient" [cardTitle]="'General Information'" [patient]="patient"></app-patient-info-accordion>
  </div>

now I want to set specific styles for elements inside of "app-patient-info-accordion" and I literally have no idea how to do it! any suggestion?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

u can use ::ng-deep on parent component to force style to child component

for example

html

<div class="main col-xl-4" style="margin-bottom: 30px;">
    <app-patient-info-accordion *ngIf="patient" [cardTitle]="'General Information'" 
    [patient]="patient"></app-patient-info-accordion>
</div>

css

.main {
   ::ng-deep {
      .title  {
        color: red;
      }
   }
}

the title class on child component will get that color style.

read more on https://blog.angular-university.io/angular-host-context/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...