Reputation: 3789
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'}">
Upvotes: 0
Views: 391
Reputation: 52
use
<div ng-style = "firstClick == true ?
{'background-color':'blue'}:
{'background-color':'red'}">
instead
Upvotes: 1
Reputation: 1313
Change
<div ng-controller="myController"
ng-style="firstClick === true?
{'background-color':'blue'} :
{'background-color':'red'}">
It's working.
Upvotes: 0
Reputation: 6459
change code to:
<div ng-style="'background-color':(firstClick?'blue':'red')">
Upvotes: 0