javascript - Passing data between angularjs and express/node without ajax -
javascript - Passing data between angularjs and express/node without ajax -
i have angularjs app running on node/express backend. i'm using passport user authentication.
when user signs in or signs up, angular controllers communicate express via $http
ajax/xhr calls. form info sent, node/express/passport process data, , homecoming json info user's info (i.e. username).
angular uses user info update templates, i.e. {{user.username}}
the problem if user refreshes entire page, angular loses user information. they're still logged in - req.user
still contains info - angular doesn't know it.
i'd avoid ajax phone call check if user logged in. that'll http phone call every new visit...
i can pass user info jade template directly, can't updated angular later.
i prefer ngstorage
just check sample illustration given below, come in want text field , refresh browser , see
working demo preview
jsfiddle
since angularjs
module makes web storage working in angular way. contains 2 services: $localstorage
, $sessionstorage
.
differences other implementations
no getter 'n' setter bullshit - right angularjs homepage: "unlike other frameworks, there no need [...] wrap model in accessors methods. plain old javascript here." can enjoy same benefit while achieving info persistence web storage.
sessionstorage - got often-overlooked buddy covered.
cleanly-authored code - written in angular way, well-structured testability in mind.
no cookie fallback - web storage beingness readily available in browsers angularjs officially supports, such fallback largely redundant.
javascript node.js angularjs express
Comments
Post a Comment