Skip to content

ngClass and conditions #17274

Closed
Closed

Description

@nauw

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When using ngClass Directive with 2 conditions, it seems that similar class used in both are removed when the first condition is true.

Consider the following code to display standard Bootstrap alert if the server is online or offline.

<div [ngClass]="{'alert alert-danger': serverStatus!='online','alert alert-success': serverStatus==='online'}">

Expected behavior

Expected result is

<div class="alert alert-danger">Server is not online</div>
or
<div class="alert alert-success">Server is online</div>

Result is

<div class="alert-danger">Server is not online</div> -- Missing class 'alert'
or
<div class="alert alert-success">Server is online</div> -- OK

Minimal reproduction of the problem with instructions

Pushing the test as far as i can, every similar class existing on both condition are "removed" when the first condition is true.

Just for the sake of demonstration.

<div [ngClass]="{'alert alert-success': serverStatus!='online','alert alert-success': serverStatus==='online'}">

Result is

<div >Server is not online</div> -- no class at all
or
<div class="alert alert-success>Server is online</div> -- OK

Please tell us about your environment:
MacOSX

  • Angular version: 4.0.X

  • Browser: [all]

  • Language: [TypeScript ]

Thank you for your review.

Arnaud

Activity

  1. pkozlowski-opensource commented on Jun 6, 2017

    @pkozlowski-opensource
    Member

    Duplicate of #5763 - please check #5763 (comment) for more details.

  2. angular-automatic-lock-bot commented on Sep 11, 2019

    @angular-automatic-lock-bot

    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.

  3. locked and limited conversation to collaborators on Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common package

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions