Open automatically a modal when string variable = nothing


#1

Hi !
I try to make an exercise, an app who ask your name :

Well, I made a modal (where you record your name) but I want that this modal open only when name = ’ ’ (no name saved).

Well this is my controller (for the modal) :

.controller('HomeCtrl', function($scope, $ionicModal) {
    /* Modal */
    $ionicModal.fromTemplateUrl('templates/your-name-modal.html', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    //Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });

});

I have two questions :
**- How to save a string variable ? I don’t understand the principle of Local storage.
- How to open automatically a modal when string variable = ’ ’

if (variable name = ’ ’ (no name))
{
$scope.modal.show();
}

when (submit is clicked)
{
save name in var name (in local storage)
}

My modal :

    <label class="item item-input">

        <input type="text" placeholder="Your name" ng-model="firstName">
    </label>
    <button class="button button-block button-dark" ng-click="modal.hide()">
        Submit
    </button>
    <p><br></p>
    <div class="centered"><img src="../img/logo.png" alt="MoveForward Logo"/></div>
</ion-content>

Thanks for your help ! Have a good day ! :smile: