I have an li element in which we are calling a method SiteAssetStyleForShiftedAsset like this:
JavaScript
x
4
1
<li class="holder-white title-holder" data-ng-style="{{SiteAssetStyleForShiftedAsset()}}">
2
3
</li>
4
and from our javascript controller it being called like this:
JavaScript
1
23
23
1
function SiteAssetStyleForShiftedAsset() {
2
3
var isPPMJob = localStorage.getItem("IsPPMJob").toUpperCase();
4
5
var shiftingAsset = $scope.addClassForShiftingAsset;
6
7
if (isPPMJob == "FALSE") {
8
9
// it is working fine here. Margin is being applied correctly.
10
return { "margin-right": "50px" };
11
}
12
else if (isPPMJob == "TRUE") {
13
if (shiftingAsset.toUpperCase() == "TRUE")
14
{
15
//it is not working fine on this line. Margin is not being applied.
16
return { "margin-right": "50px" };
17
}
18
else {
19
return { "padding-right:": "15px" };
20
}
21
}
22
}
23
So it is working fine in the first if (isPPMJob == “FALSE”) but in else if where we are checking shiftingAsset.toUpperCase() == “TRUE” that margin is not being applied.
Tried alerts on all conditions they are showing fine but margins are causing problems.
Advertisement
Answer
I found solution for that problem. The problem was with HTML code we were using data-ng-style like this
JavaScript
1
2
1
data-ng-style="{{SiteAssetStyleForShiftedAsset()}}"
2
instead of this we have to use it like
JavaScript
1
2
1
data-ng-style="{'margin-right': SiteAssetStyleForShiftedAsset()}"
2
Then in JS controller just return value of margin i.e. “10px” , “50px”,etc
function SiteAssetStyleForShiftedAsset() {
JavaScript
1
14
14
1
var isPPMJob = localStorage.getItem("IsPPMJob").toUpperCase();
2
3
var shiftingAsset = $scope.addClassForShiftingAsset;
4
5
if (shiftingAsset == "false"){
6
//alert("abc");
7
return "10px";
8
//return { "padding-right:": "15px" };
9
}
10
else{
11
return "50px";
12
}
13
}
14