Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass value from ts file to scss file in same component in angular 2+?

This is my component

export class myComponent implements onInit {

private outageCount;

ngOnInit(){

    ....subscribe((data) => {
    this.outageCount = Object.keys(data).length;

})
}

I need to pass the outageCount to my css before CONTENT

:host ::ng-deep app-settings-panel {
    &:before{
        //content:"4";
        content:attr(outageCount);
        background: #941313;
        position: absolute;
        top: 3px;
        left: 22px;
        border-radius: 50%;
        height: 13px;
        width: 13px;
        border: 1px solid #ffffff;
        color: white;
        font-size: 8px;
        text-align: center;
        line-height: 13px;
    }

How can i pass the outageCount value from my component to css :before content.

Any suggestions would be appreciated!

like image 269
Ramya S Avatar asked Mar 20 '18 09:03

Ramya S


People also ask

Can we use TS variable in SCSS?

Sometimes you need to share variables between CSS (or SCSS) and Typescript, for example, if you have a list of colors in your SCSS file and need to check the variable names in typescript to be sure is an available color.


1 Answers

I'm passing this as attribute in my html like below

 [attr.outage-count]="outageCount"

I css, i updated like this

   :host ::ng-deep app-settings-panel {
        &:before{
            content: attr(outage-count);
            ......
        }
    }

This works for me!! Thanks for all those who tried helping me!

like image 135
Ramya S Avatar answered Sep 17 '22 16:09

Ramya S