How to use an ng-class in the <html> tag

Asked

Viewed 1,011 times

0

I’m using the Angularjs framework and need my tag to receive a dynamic class example:

<html lang="en" id="ng-app" ng-app="app" ng-class="app.title">
</html>

This app.title will receive a value from Mongo.

Can anyone tell me if this is possible? And if this way it is possible to return the class name knowing that I have a string in this field?

  • I don’t think anyone knows that answer. The attribute ng-class works in normal elements, but in HTML I do not know. Probably you will have to define the attributes ng-app, ng-controller and only then ng-class maybe it works, everyone on the tag html. Test. It’s the easiest way to find out.

1 answer

1


Translating from the Angularjs documentation(https://docs.angularjs.org/api/ng/directive/ngClass)

The ngClass directive allows you to dynamically change the CSS of an HTML element by making a databinding of an expression that represents all the classes to be added. The directive operates in three different ways, depending on which of the three types of the following expression is evaluated:

  1. If the expression is a string, the string must contain several classes separated by spaces;
  2. If the expression is an array, each element of the array must be a string with one or more space-separated classes;
  3. If the expression is an object, then for each key-value item of the object the corresponding key will be used as class name.

Take this plunker as an example: http://plnkr.co/edit/? p=preview

Browser other questions tagged

You are not signed in. Login or sign up in order to post.