timeout in AngularJS

0

I'm doing an application in ionic, which uses Angular.js as a base. I have a native splash of ionic with 3s and soon it enters the controller splash that has a video of 5s with an animation. I would like to know how to redirect to another controller, log in as soon as the video is gone. Can anyone help me with this?

    
asked by anonymous 24.10.2016 / 01:26

3 answers

2

To do what you want, whenever the application starts you redirect the route to any screen, to do this, do a state go in the run:

angular.module('myApp', [])
  .config(something => {})
  .run(function ($state) {
    $state.go('rotaDaTelaComVideo');
  });

According to Angular documentation: Documentation

  • config is called first at module initialization.

  • run is called once at module initialization, right after config.

  • Compilation of policies and others ...

  • Controllers are created.

  • Policy link, if any.

  • In this way, it is safe to call a route in the run, at the same time that in the next iteration of the Angular it will load its module.

    Bonus :

    Still, if you want the video to run only once, you can save a flag in the localStorage:

    angular.module('myApp', [])
      .config(something => {})
      .run(function ($state, $window) {
        if ($window.localStorage['alreadyShown'] !== true) {
          $state.go('rotaDaTelaComVideo');
          $window.localStorage['alreadyShown'] = true;
        }
      });
    

    So it will only run the first time the user starts the application, or after clearing all data from the cache.

        
    24.10.2016 / 15:33
    0

    Inject $state to your Controller and after the video ends use $state.go .

    function goLogin(){
    $state.go("app.login-new");
    }
    
        
    24.10.2016 / 02:05
    0
    <ion-view title="splash" id="splash" hide-nav-bar="true">
        <ion-content padding="true" class="has-header vcenter" scroll="false">
    <video preload="metadata" autoplay="autoplay" webkit-playsinline="webkit-playsinline" class="videoPlayer">
      <source src="video/splash.mp4" type="video/mp4"/>
    </video>
        </ion-content>
    </ion-view>
    

    Controller

    .controller('splash', ['$scope', '$stateParams', 
    function ($scope, $stateParams) {
    
    
    }])
    
        
    24.10.2016 / 13:02