arqam
arqam

Reputation: 3789

Ng-Style conditional variable change not getting showing in html

So I have my ng-style with conditional parameters, and it executes the conditional changes when the page is loaded.

But when I make some change in the conditional operator at runtime, in the controller side, the conditional parameter is not reflected in the html side.

I tried using $scope.$apply() and $scope.reload() but it doesn't give the required results.

<div ng-style="({{firstClick}})? 
     {'background-color':'blue'} :
     {'background-color':'red'}">

JSFiddle

Upvotes: 0

Views: 391

Answers (3)

tritims
tritims

Reputation: 52

use

<div ng-style = "firstClick == true ?
     {'background-color':'blue'}: 
     {'background-color':'red'}">

instead

JSfiddle

Upvotes: 1

Rahi.Shah
Rahi.Shah

Reputation: 1313

Change

<div ng-controller="myController"
     ng-style="firstClick === true? 
     {'background-color':'blue'} :
     {'background-color':'red'}">

It's working.

Upvotes: 0

Behnam
Behnam

Reputation: 6459

change code to:

<div ng-style="'background-color':(firstClick?'blue':'red')">

Upvotes: 0

Related Questions