Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何消除角度传感器的故障/延迟?_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 如何消除角度传感器的故障/延迟?

Javascript 如何消除角度传感器的故障/延迟?,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我使用此代码仅当用户第一次访问应用程序时才显示splashscreen。这部分是有效的,但不能正常工作 当之前已经访问过该应用程序的用户再次访问时,它首先显示splashscreen仅1秒钟,因此会延迟一秒,然后最终进入主屏幕。。。所以这就像一个小故障 主控制器: $urlRouterProvider.otherwise("/splash"); 在我的splashscreen控制器中,我有: if (localStorage['firstTimeLoad']!='TRUE'){

我使用此代码仅当用户第一次访问应用程序时才显示splashscreen。这部分是有效的,但不能正常工作

当之前已经访问过该应用程序的用户再次访问时,它首先显示splashscreen仅1秒钟,因此会延迟一秒,然后最终进入主屏幕。。。所以这就像一个小故障

主控制器:

$urlRouterProvider.otherwise("/splash");
在我的splashscreen控制器中,我有:

  if (localStorage['firstTimeLoad']!='TRUE'){
        localStorage['firstTimeLoad']='TRUE';
        $state.go('splash'); 
    }
    else {
        $state.go('home');
    }

我的问题是:我如何摆脱这个延迟/故障?如果用户可以看到不再需要看到的东西,我觉得这是非常不专业的。

在你的爱奥尼亚项目的根文件夹中应该有一个config.xml。在里面你应该可以找到这些选项

<preference name="SplashScreenDelay" value="2500" />
<preference name="FadeSplashScreenDuration" value="400" />

根据您的需要调整它们。

有两种可能- 1或者您已经提到splashscreen状态是您的默认路由器,一旦在splash控制器下执行,那么只有您在检查并相应地让用户着陆

2或如果不是,splashscreen必须是您的父状态

我建议您将此逻辑移到父状态,并确保splashscreen不是您的父状态。

使用ui路由器,您可以有几种方法

路由器配置 onStateChangeStart
您可以将其放在运行中块的主控制器中

使用以下代码定义路由中的初始状态

$stateProvider.state("home", {
    // dummy template and resolve things
    template: '<h1>{{title}}</h1>',
    resolve: { title: 'My Contacts' },
    controller: function($scope, title){
    $scope.title = title;
},
onEnter: function($state){
   if (localStorage.firstTimeLoad != true){
     localStorage.firstTimeLoad= true;
     $state.go('splash'); 
   }
}
})


它的代码经过测试,工作正常。

此代码段如果不是第一次,也不会显示闪屏,因此它一定是在其他地方意外显示闪屏。可能与您的路由定义有关,可能是状态声明默认设置为home,之后可能会进行条件检查。我不认为这是因为我的路由定义。顺便说一句,我把这个片段放在我的splashscreen控制器中。在ui路由器中,使用resolve选项等待导航@maurycy是什么意思?你能提供一个例子/片段吗?然后该怎么做?这并不能消除这个小故障,可能。。。或者会吗?您可以将SplashScreenDelay设置为0表示无延迟,也可以使用一些值进行播放。至少角度1非常慢,有时视图需要一些时间来渲染。我检查了这个,发现它们已经在0上,所以这不是我的修复方法。我有:$urlRouterProvider.Others/splash;。您的意思是更改或删除此项?是的,默认情况下,您需要将用户重定向到其他状态。你应该在里面写这个逻辑。好吧,那么我应该用什么来改变它呢?现在要溅水了。我应该移除它吗?我应该把它换成家吗?我不知所措。$urlRouterProvider.others/home;将其添加到您的家庭控制器-如果localStorage['firstTimeLoad']!='TRUE'{localStorage['firstTimeLoad']='TRUE';$state.go'splash';}我按照你的方式做了。。。但问题仍然存在。现在,我们只是将故障的位置从主页切换到splashscreen,仅此而已。它的工作方式没有改变。。。因为当你是第一次访客时,你只会先看到主屏幕一秒钟,然后才被引导到splashscreen。最后一个片段放在哪里?onStateChangeStart下面的那个,我的意思是?我在下面放了一条注释,你可以把它放在运行块中,也可以放在主控制器中,如果你有,好的,但是什么是rootscope?我可以把它放在主控制器中吗?我用了$rootScope,但你也可以用$scope,这是一个角度服务,你可以使用它,但不工作。无法让一台机器工作。第二个片段也失败了。可能是因为$urlRouterProvider.others/splash,但是无法让它工作。嗯,模板的作用是什么?那决心呢?你能先解释一下代码吗?它定义一个状态的方式,模板用于ui,解析是将数据传递到你的状态。你能粘贴你的州代码定义吗?我可以这样解释:myApp.configfunction$stateProvider,$urlRouterProvider,$ionicConfigProvider{$stateProvider.state'splash',{url:'/splash',templateUrl:'./templates/splash.html',controller:'SplashController'}这就是您所需要的-///////myApp.configfunction$stateProvider、$urlRouterProvider、$ionicConfigProvider{$stateProvider.state'splash'、{url:'/splash',templateUrl:'./templates/splash.html',controller:'SplashController',oneter:function$state{if localStorage.firstTimeLoad!=true{localStorage.firstTimeLoad=true;$state.go'splash';};
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) {
    if (localStorage['firstTimeLoad'] != 'TRUE') {
        event.preventDefault()
        localStorage['firstTimeLoad'] = 'TRUE';
        $state.go('splash');
    }
})
$stateProvider.state("home", {
    // dummy template and resolve things
    template: '<h1>{{title}}</h1>',
    resolve: { title: 'My Contacts' },
    controller: function($scope, title){
    $scope.title = title;
},
onEnter: function($state){
   if (localStorage.firstTimeLoad != true){
     localStorage.firstTimeLoad= true;
     $state.go('splash'); 
   }
}
})