Issue
what's the $cookies on AngularJS in Angular 4/5?
for example in AngularJS
let app = angular.module('myApp', ['ngCookies']);
app.controller('MainController', MainController);
MainController.$inject = ['$scope', '$cookies'];
function MainController($scope, $cookies){
$cookies.put('msg', 'Hello World');
$scope.msgFromCookie= $cookies.get('msg');
}
Solution
There are several npm packages that you can use for handling cookies in Angular4/5. Such as 'ngx-cookie-service, you can get it with npm
npm install ngx-cookie-service --save
You add the cookie service to your module as a provider (As you would with any service), then inject it into a component and use it.
import { CookieService } from 'ngx-cookie-service';
constructor(private cookieService: CookieService) { }
this.cookieService.set('msg', 'Hello World');
this.cookieService.get('msg');
Answered By - theriddle2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.