AngularJS - get DB data(in js) / use ng-show(in html)

412 Views Asked by At

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?

2

There are 2 best solutions below

2
On BEST ANSWER

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

0
On

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.