1

I am trying to get date from my db. And with the data I wanna use ng-show.

In my js file :

 httpq.post('/data/instructor.asmx/PasswordAgain', postData)
        .then(function(data) {
            $scope.informs = JSON.parse(data.d.result).Table;

            if ($scope.informs.length > 0) {
                $scope.Ins_Checking = $scope.informs[0];
            }

        })
        .catch(function(data, status) {
            $.showToast('error', $filter('translate')('MSG.ERROR'));
        })
        .finally(function() {
            console.log("finally finished1");
        });

In my html file(Test Code):

<div ng-repeat="inform in informs">
  {{inform.Ins_Check}}
</div>

This is working.

Question :

<div ng-show="Ins_Check != 'O'">
    Input Password : <input type="password">
</div>
<div ng-show="Ins_Check == 'O'">
    The password is Correct!
</div>

With the DB data(inform.Ins_Check), If the data is not 'O', show Input Password code. Or if the data is 'O', show the words 'The password is Correct!'.

What code should I input?

Or should I use another function?

3
  • What is not working? Why don't you have an else clause? Commented Aug 11, 2015 at 6:34
  • Shouldn't it be $scope.Ins_Checking = $scope.informs.length ? $scope.informs[0].Ins_Check: 'O';? Commented Aug 11, 2015 at 6:35
  • $scope.Ins_Checking = $scope.informs.length ? $scope.informs[0].Ins_Check: 'O'; << this is working too. thanks Commented Aug 27, 2015 at 9:14

2 Answers 2

1

ng-show and ng-hide are worked on truthy and falsy values. if Ins_Check has Boolean value then you do not need to compare with 0 or 1. Simple write ng-show="Ins_Check" and ng-hide="!Ins_Check"

Working example here

Sign up to request clarification or add additional context in comments.

2 Comments

Please always add the code to your answer not only a link to plnkr
Hi Thanks for your reply. I got the data 'O' or 'X' from db. So I modify the code like this. <div ng-show="inform.Ins_Check == 'X'" ng-repeat="inform in informs"> <div ng-show="inform.Ins_Check == 'O'" ng-repeat="inform in informs">
0

Sorry for the delay response.

The code that you are using is the right one for ng-show. The condition variable that you are checking is wrong.

In your js, you have used $scope.Ins_Checking for assigning the value. But in the ng-show comparison, you are using Ins_Check which is not available with your example.

So try with replacing Ins_Check with Ins_Checking. I hope this works.

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.