0

I am new with web API and angularjs.

I have a web app with login form. I have to check if the web-app is running first time in browser, but I don't know any way to do that.

Any way to check it using angularjs? Thanks in advance.

3
  • elaborate on the exact version of angularjs you're using to get a more detailed answer Commented Feb 7, 2018 at 3:15
  • @shaunhusain, Thanks for quick response. I'm using angularjs v1.6.4 Commented Feb 7, 2018 at 3:44
  • No problem posted a bit more detail below let me know if you can't work it out but should be able to include the angular-cookies.js and ngCookies dependency on your main module then can use it to put or get cookies (the capability of the built in service hasn't been that great in the past so be sure to check specific docs for your version of angular/cookies module or alternatively look for third party services/modules) It fails on here due to running in an iframe I'm pretty sure. Commented Feb 7, 2018 at 3:56

1 Answer 1

2

You can use cookies or local storage on the client side to store information in the browser to "know" if a user has been to the page.

https://docs.angularjs.org/api/ngCookies/service/$cookies

Doesn't appear this is really updated but believe it is a usable solution if you want to use local storage instead: https://github.com/gsklee/ngStorage

angular.module('cookiesExample', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
  // Retrieving a cookie
  this.favoriteCookie = $cookies.get('myFavorite');
  if(this.favoriteCookie) {
    console.log('they have been here before oooo spooky')
  }
  // Setting a cookie
  $cookies.put('myFavorite', 'oatmeal');
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular-cookies.min.js"></script>


<div ng-app="cookiesExample" ng-controller="ExampleController as exc">
  {{exc.favoriteCookie}}
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.