0

I have a call in AngularJS to $http Get which is returning data. I have a boolean field PassFail that currently appears as "true" or "false". I want it to display "Pass" or "Fail". I've tried adding a PassFail function in $scope and $rootScope but nothing works for me. I think there is some easy solution but it will probably take me days to figure this out on my own. Can you help?

    var oApp = angular.module("myApp", []);

    oApp.controller("certificationsCtrl", function ($scope, $http)
    {
        $scope.Exams = {};

        $scope.GetPassFail = function (passFail)
        {
            return passFail ? "Pass" : "Fail";
        };

        $scope.ShowExams = function (certificationID)
        {
            var url = "http://localhost:49861/api/Exams?id=" + certificationID + "&extra=0";

          $http({
                method: "GET",
                url: url
            }).then(function mySuccess(response)
            {
                $scope.Exams = response.data;
            }, function myError(response)
            {
                alert("error response.statusText = " + response.statusText);
            });
        }
    });

<tr ng-repeat="x in Exams">
                <td style="border: 1px solid black;">{{ x.ExamNumber}}</td>
                <td style="border: 1px solid black;">{{ x.ExamShortName }}</td>
                <td style="border: 1px solid black;">{{ x.PassFail | GetPassFail }}</td>
MM-dd" }}</td>
            </tr>

2 Answers 2

2

Why you don't process this inside html with

{{ x.PassFail ? "Pass" : "Fail" }}
Sign up to request clarification or add additional context in comments.

1 Comment

Both answers work, and while Kethansri answered my question more directly, I think we would all agree this is a better solution. Simpler is almost always better. Thanks Simon.
1

Try <td style="border: 1px solid black;">{{GetPassFail(x.PassFail)}}</td>

Comments

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.