无论如何都要检查第一次调用"/"
路由的时间吗?
我的意思是,检查首次打开应用主页的时间。
答案 0 :(得分:5)
假设您有一个单页应用程序的应用程序,如果您想要运行一次的代码,请使用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
});
答案 1 :(得分:2)
您可以使用Cookie。如果用户第一次访问您的应用程序,那么他没有cookie,但下次他会有。
.controller('MainCtrl', function ($scope, $cookies, $cookieStore, $log) {
$scope.showHello = !$cookies.visited;
$cookies.visited = 'yes';
});
视图:
<div ng-if"showHello">
Hellow, stranger!
</div>
不要忘记加载ngCookes模块 angular.module('App',['ngCookies']);