Add a login page in my Onsenui app

charlesen picture charlesen · Mar 3, 2014 · Viewed 7.3k times · Source

I'd like to set a login page before entering the main page. How can I do that just before this instruction :

<ons-screen page="sliding_menu.html"></ons-screen>

I use The Monaca IDE

Thanks for the help

Charles

Answer

Tamura picture Tamura · Mar 7, 2014

You can try this way:

index.html

<ons-screen page="login.html"

login.js

function LoginController($scope){
    $scope.login = function(id, password){
        $scope.ons.screen.presentPage('sliding_menu.html');
    }
}

login.html

    <div class="page center" ng-controller="LoginController">
    <div class="row">
        <div class="col">
            <ons-text-input placeholder="id" ng-model="id">             
            </ons-text-input>
        </div>
    </div>
    <div class="row">
        <div class="col">
            <input type="password" placeholder="password" ng-model="password" class="topcoat-text-input">
        </div>
    </div>

    <div class="row">
        <div class="col">
            <ons-button ng-click="login(id, password)">
                Login
            </ons-button>
        </div>
    </div>
</div>

Demo: http://onsenui.github.io/stackoverflow/sliding_menu_login/app/

Download src: http://onsenui.github.io/stackoverflow/sliding_menu_login.zip