Checking if user exists using AngularJS and ng-if
<p>I am building a cross-platform app using Onsen UI, Monaca and AngularJS. I need to check if a user exists based on the UserID they enter. If the UserID is found, then the name is returned to me, else the user wont be able to proceed to the next screen.</p>

<p>I send the UserID via API call ($http) and get a JSON object as a response. When I enter a UserID I can retrieve the JSON object (tested and working) but I am stuck on authentication.</p>

<p>When the user clicks the LOG IN button, I show a modal (ons-modal) window with a message of the users name if the user is found, but I am stuck on showing the message LOGIN FAIL if no user is found.</p>

<p>Is there perhaps a better way to handle this rather than a modal window?</p>

<p>Below is my code. And below is an example of the JSON that is returned.</p>

<pre><code>[{"employee_name":"John Doe"}]
</code></pre>

<p>There is also a Controller that handles the API calls and it can be assumed this is working OK as I am able to get user names - but just stuck on authentication.</p>

<p><strong>login.html</strong></p>

<pre><code>&lt;div style="text-align: center; color: #889DA8"&gt;
    Enter your&lt;br&gt;&lt;strong&gt;User ID&lt;/strong&gt;
&lt;/div&gt;

&lt;form class="login-form" style="text-align: center" name="myForm"&gt;
    &lt;section style="padding: 8px"&gt;
        &lt;input type="password" class="text-input--underbar" required minlength="3" maxlength="4" ng-model-options="{ debounce : 800 }" placeholder="User ID" ng-model="userIDSearch" &gt;
    &lt;/section&gt;

    &lt;section style="padding: 0 8px 8px"&gt;
        &lt;ons-button var="saveBtn" ng-disabled="myForm.$invalid" modifier="large" onclick="modal.show('modal')"&gt;Log In&lt;/ons-button&gt;
    &lt;/section&gt;
&lt;/form&gt;

&lt;!-- Displays Modal Login Confirmation Screen --&gt;
&lt;ons-modal var="modal"&gt;
    &lt;div class="alert-dialog-mask"&gt;&lt;/div&gt;

    &lt;div class="alert-dialog alert-dialog--android"&gt;
        &lt;div class="alert-dialog-title alert-dialog-title--android"&gt;
            &lt;div style="text-align: center"&gt;Please confirm your name&lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="alert-dialog-content alert-dialog-content--android"&gt;
            &lt;div style="text-align: center; padding-top: 10px; padding-bottom: 15px; padding-left: 10px; padding-right: 10px;"&gt;
                &lt;p ng-repeat="userID in userIDs"&gt;

                    &lt;!-- If returned value != 0 then we have a valid User --&gt;
                    &lt;!-- NOT WORKING HERE --&gt;
                    &lt;span ng-if="userID.employee_name !== 0 "&gt;
                        &lt;strong&gt;
                            {{userID.employee_name}}
                        &lt;/strong&gt;    
                    &lt;/span&gt;
                    &lt;!-- NOT WORKING HERE --&gt;        
                    &lt;span ng-else&gt;
                        &lt;strong&gt;
                            User ID not found. Please try again.
                        &lt;/strong&gt;    
                    &lt;/span&gt;                           
                &lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="alert-dialog-footer alert-dialog-footer--one"&gt;
            &lt;button class="alert-dialog-button alert-dialog-button--one" ng-click="modal.hide()"&gt;Cancel&lt;/button&gt;
            &lt;button class="alert-dialog-button alert-dialog-button--primal alert-dialog-button--one" ng-click="myNavigator.pushPage('vehicle-id.html', {animation: 'slide'});" )&gt;Ok&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/ons-modal&gt;
</code></pre>

<p>Would this be better handled in the app-controller perhaps?</p>

<p><strong>appController.js</strong></p>

<pre><code>// App Controller Start
angular.module("myApp", ['onsen']).controller("appController", function($scope, $http)
{
    // Watch for changes in the User ID text field
    $scope.$watch('userIDSearch', function()
    {
       fetchUSerID(); 
    });

    // Initialising the search field
    $scope.userIDSearch = "";

    function fetchUSerID()
    {
        $http.get("mymadeupdomain/api/login.php?userid=" + $scope.search).success(function(data)
        {
            $scope.userIDs = data;
        }); 
    }
});
</code></pre>