如何在基于条件的离子框架中加载第一页

时间:2014-12-22 11:54:49

标签: angularjs ionic-framework

我是Ionic Framework的新手,用于开发移动应用程序。

这是情景:

当用户第一次打开应用程序时(window.localStorage.getItem(“pin”)== null),它会显示输入PIN的表单,然后将其存储为LocalStorage中的“pin”。

当用户第二次打开它时(window.localStorage.getItem(“pin”)!= null)它会显示仪表板页面。

我怎样才能做到这一点?

我使用CLI“ionic start ionicApp tabs”中的“tabs”模板。

我在app.js底部对此进行了修改:

if (window.localStorage.getItem("pin")==null) {
    $urlRouterProvider.otherwise('/pin/set');
  } else {
    $urlRouterProvider.otherwise('/tab/dash');
  }

在app.js的头部添加了这个:

.state('pin.set', {
    url: '/pin/set',
    views: {
      'pin-set': {
        templateUrl: 'templates/pin-set.html',
        controller: 'PinSetCtrl'
      }
    }
  })

在controllers.js中添加了这个:

.controller('PinSetCtrl', function($scope) {})

根据我上面的代码,它只显示空白页面,而不是显示“pin-set.html”。

请多多帮助,谢谢。

1 个答案:

答案 0 :(得分:4)

首先,app.js仅适用于您应用程序页面的路径,因此您不应该在路由本身之外放置任何类型的代码。

你应该尝试在你的家庭控制器中做这样的事情(其中包含param $状态):

if(window.localStorage.getItem('firstTime') == null) //if first time
    $state.go('app.signUp'); //go to sign up view.
else
    $state.go('app.signIn'); //if not first time go to sign in view.