设置页面在Ionic应用程序中启动

时间:2017-01-06 08:41:52

标签: angularjs ionic-framework

在我创建模板文件夹和文件login.html之后,我创建了离子应用程序空白。 现在我想在启动时设置我的应用程序login.html页面将显示。 我尝试使用代码:

app.js

angular.module('starter', ['ionic'])
    .run(function($ionicPlatform) {
        $ionicPlatform.ready(function() {
            if (window.cordova && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);
            }
            if (window.StatusBar) {
                StatusBar.styleDefault();
            }
        });
    })
    .config(function($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('login', {
                url: '/login',
                abstract: true,
                templateUrl: 'templates/login.html',
            })

的index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link rel="manifest" href="manifest.json">
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="cordova.js"></script>
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">
  </body>
</html>

但启动时显示白页。 我该怎么办呢? 谢谢大家!

1 个答案:

答案 0 :(得分:2)

您已配置状态,但未设置默认状态。您也没有<div ui-view></div>来启动州提供商。

如果您想将登录页面作为起始页面,则必须如此配置:

.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('login', {
            url: '/login',
            // remove abstract true
            templateUrl: 'templates/login.html',
        })

    // Set default to /login
    $urlRouterProvider.otherwise("/login");
})

然后在你的html中让$stateProvider知道你的视图导航的根目录:

<body ng-app="starter">
    <div ui-view></div>
</body>