简体   繁体   中英

Where should I put the code to change class of the parent element in Angular?

I am building a plugin to a larger application that uses Angular.
The plugin is basically an include in a larger HTML document.

I want to change class of the plugin's parent element.

I can't change parent HTML directly, so where should I put the code to do addClass ?

Directive feels like an overkill (and it would either be very specific, or I would have to re-implement whole ng-class ). But it might be a fair answer.

I think directive is a way to do it. From Angular's documentation:

Manipulate DOM — Controllers should contain only business logic. Putting any presentation logic into Controllers significantly affects its testability. Angular has databinding for most cases and directives to encapsulate manual DOM manipulation.

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