简体   繁体   中英

how to add new class to Angular JS ng-class with dollar sign?

I've recently joined a team, and they are using AngularJS. Their codes is:

html:

<div ng-class="$ctrl.styles.className">I need to add one new class here</div>

If I want to put more classes into one div, I can easily make the classes in to an array, like this:

<div ng-class="[$ctrl.styles.classNameOne,$ctrl.styles.classNameTwo]"> But how to add the third new class into the array??</div>

CSS:

.classNameOne {
    position: fixed;       
}
.classNameTwo{
    color:red;
}

But how to add more new classes into the array of div ? I tried many ways, but I don't know how to add new classes into the array of the <div> , because the class must with the dollar sign: $ctrl.styles.className .

Could anyone tell me how to add new classes with dollar signs?

As per the dot notation, $ctrl.styles.className should be pointing to a variable className inside styles object inside your controller referenced by ctrl .

So change the value of className inside your controller to whatever class that is defined in your CSS file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM