2

I have an li element in which we are calling a method SiteAssetStyleForShiftedAsset like this:

<li class="holder-white title-holder" data-ng-style="{{SiteAssetStyleForShiftedAsset()}}">
 ...
</li>

and from our javascript controller it being called like this:

function SiteAssetStyleForShiftedAsset() {

    var isPPMJob = localStorage.getItem("IsPPMJob").toUpperCase();

    var shiftingAsset = $scope.addClassForShiftingAsset;

    if (isPPMJob == "FALSE") {

        // it is working fine here. Margin is being applied correctly. 
        return { "margin-right": "50px" };
    }
    else if (isPPMJob == "TRUE") {
        if (shiftingAsset.toUpperCase() == "TRUE")
        {
            //it is not working fine on this line. Margin is not being applied.
            return { "margin-right": "50px" };
        }
        else {
            return { "padding-right:": "15px" };
        }
    }
}

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.

3
  • Have you done a console.log or a breakpoint to test whether you're actually hitting the line of code that applies the margin? Commented Dec 9, 2021 at 16:21
  • 1
    Yes @JacobStamm I have added an alert just before the line that is applying the margin and I have also inspected the element and it was showing data-ng-style="{"margin-right":"50px"}" but on the view nothing was changed !!! Commented Dec 9, 2021 at 19:04
  • 2
    Since both the first and second returns return the exact same value, the only possible thing that's different between those two conditions is the value of $scope.addClassForShiftingAsset. Not a solution, but it is somewhere to look Commented Dec 9, 2021 at 19:07

1 Answer 1

1

I found solution for that problem. The problem was with HTML code we were using data-ng-style like this

data-ng-style="{{SiteAssetStyleForShiftedAsset()}}"

instead of this we have to use it like

data-ng-style="{'margin-right': SiteAssetStyleForShiftedAsset()}"

Then in JS controller just return value of margin i.e. "10px" , "50px",etc

function SiteAssetStyleForShiftedAsset() {

    var isPPMJob = localStorage.getItem("IsPPMJob").toUpperCase();

    var shiftingAsset = $scope.addClassForShiftingAsset;

    if (shiftingAsset == "false"){
                //alert("abc");
         return "10px";
                //return { "padding-right:": "15px" };
    }
    else{
        return "50px";
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't explain the first return { "margin-right": "50px" } where your code snippet says it works fine. I suspect it wasn't actually working then.
@Taimoor you are right. this is just another way of doing it and if it is working like this then we can go with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.