Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng-class equivalent behaviour #2025

Closed
jbdeboer opened this issue May 20, 2015 · 11 comments · Fixed by #2720
Closed

ng-class equivalent behaviour #2025

jbdeboer opened this issue May 20, 2015 · 11 comments · Fixed by #2720
Assignees
Labels
effort2: days feature Issue that requests a new feature
Milestone

Comments

@jbdeboer
Copy link

[If this already exists, a pointer to the docs would be awesome.]

In AngularDart, I have an element:
<div class="a" ng-class="someExpr"></div> where someExpr evaluates to "b c".

The rendered output is <div class="a b c"></div>.

How do I use this pattern in Angular 2?

@pkozlowski-opensource
Copy link
Member

This syntax is not currently supported with the existing class directive (it understand only object literals syntax right now). Last time I've discussed string-based with @IgorMinar it sounded like we might not want to support it in ng2 as it makes it easy to "hard-code" CSS classes in JS/Dart code.

We should probably re-discuss this and have definitive stance on this one.

@jbdeboer
Copy link
Author

The current best option, AFAICT, is to re-write the above example as:
<div [class-name]="'a ' + someExpr"></div>

which is super-fugly.

@SekibOmazic
Copy link
Contributor

@jbdeboer I had a similar problem and used following syntax:

<div class="a" [class.b]="bExpr" [class.c]="cExpr"></div>

There is also the CSSSelector which works with object literals, but I found it inconvenient.

@jbdeboer
Copy link
Author

@SekibOmazic Yes; but that approach would require us to rewrite our controller logic; which isn't something we are eager to do!

Thinking on the "best option" that I listed: it does not work well either, since in Angular1, we don't know if someExpr is a string, list or map without inspecting the controller. That transformation only works for strings.

@naomiblack naomiblack added this to the M10: Fixit milestone May 20, 2015
@naomiblack
Copy link
Contributor

Assigning to @mhevery and (also @IgorMinar) for discussion. Is this something that we can support in angular2, or else, what's our best recommendation for handling this pattern?

@yjbanov
Copy link
Contributor

yjbanov commented May 21, 2015

I think it's safe to support <div class="a" [class]="expr"></div> where expr evaluates to List or Map and [class] simply adds more classes to the already existing literal list.

@mhevery
Copy link
Contributor

mhevery commented May 26, 2015

I agree with @yjbanov, I think we should support it.

@mhevery
Copy link
Contributor

mhevery commented May 26, 2015

Also fix for ng-style

@mhevery mhevery modified the milestones: M9: TypeScript and Build Stability, M10: Fixit May 26, 2015
@mhevery mhevery modified the milestones: M10: GreenTea Blockers, M9: TypeScript and Build Stability May 27, 2015
@mhevery mhevery modified the milestones: M10, M9: TypeScript and Build Stability May 29, 2015
@mhevery mhevery added feature Issue that requests a new feature comp: core/templating effort2: days labels May 29, 2015
@naomiblack
Copy link
Contributor

Assigning to @vsavkin to clarify what needs to be implemented.

@pkozlowski-opensource
Copy link
Member

Had a productive chat with @vsavkin - I'm unblocked.

pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Jun 23, 2015
pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Jun 24, 2015
vicb pushed a commit to vicb/angular that referenced this issue Jun 24, 2015
vicb pushed a commit to vicb/angular that referenced this issue Jun 24, 2015
jimthedev pushed a commit to jimthedev/angular that referenced this issue Jun 30, 2015
jimthedev pushed a commit to jimthedev/angular that referenced this issue Jun 30, 2015
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.