3

Is there anyway to check when "/" route is called for the first time?

I mean, check when the home page of the app is opened for the first time.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
itsme
  • 48,972
  • 96
  • 224
  • 345

2 Answers2

5

Suppose you have an app that is a Single Page Application, if you want code that runs once, use module.run(): http://docs.angularjs.org/guide/module

angular.module('myModule', []).
  run(function($http /*or whatever*/) { 
     // here goes your code that will only run at module initialization
  });
michael
  • 16,221
  • 7
  • 55
  • 60
2

You can use cookies. If user visit your app first time then he have not cookies but next time he will have.

  .controller('MainCtrl', function ($scope, $cookies, $cookieStore, $log) {
    $scope.showHello = !$cookies.visited;
    $cookies.visited = 'yes';
  });

view:

<div ng-if"showHello">
  Hellow, stranger!
</div>

And don't forget to load ngCookes module angular.module('App', ['ngCookies']);

Vasiliy Kevroletin
  • 1,188
  • 13
  • 17