2016-08-12 104 views
1

我可以使用Angular2設置僞選擇器的樣式。angular2僞選擇器樣式

<section class="inner_content person_content backdrop poster" *ngIf="personAllMoviesArray.length > 0"> 
    <div class="personFavouritePoster"></div> 
    <div class="single_column_medium"> 
     {{id}} 
    </div> 
</section> 

CSS是

section.inner_content.backdrop:before { 

background-image: url('https://image.tmdb.org/t/p/w1440_and_h405_bestv2/fBFPLjqiLTDW3GWgWIRkhHTwAcb.jpg');} 

回答

2

你可以定義一個CSS類像

.has-before:before { 
    background-image: url('https://image.tmdb.org/t/p/w1440_and_h405_bestv2/fBFPLjqiLTDW3GWgWIRkhHTwAcb.jpg'); 
} 

,並通過一些切換可變

<section [class.has-before]="toggleVariable" 
     class="inner_content person_content backdrop poster" 
     *ngIf="personAllMoviesArray.length > 0"> 
    <div class="personFavouritePoster"></div> 
    div class="single_column_medium"> 
     {{id}} 
    </div> 
</section> 
添加撥動類