BCJTI / ng2-cookies

Simple library to deal with cookies in Angular2
64 stars 31 forks source link

Does not work the latest Angular CLI build with web pack. #27

Closed elmiguel closed 7 years ago

elmiguel commented 7 years ago

Importing the Cookie class and trying to do a check causes an Error: import { Cookie } from 'ng2-cookies/ng2-cookies'

Cookie.check('cookName')

Error in web pack build: Property 'check' does not exist on type 'typeof Cookie'

Set and Gets do not work as well, as there is nothing in the dev console or storage of the newly created (attempted) cookies.

Tried some tests:

  Cookie.check('searchTerm')

  if(!Cookie.get('searchTerm')){
    Cookie.set('searchTerm', term)
  }

  if(!Cookie.get('searchActive')){
    Cookie.set('searchActive', 'true')
  }

None of these tests have work as of yet.

Bigous commented 7 years ago

Hi @elmiguel

Could you post the steps to reproduce this issue?

[]'s

elmiguel commented 7 years ago

Sure,

First I installed via npm:

npm install ng2-cookies --save

I imported the package to the main app (although doesn't seem to be injectable?):

import { Cookie } from 'ng2-cookies'

But the I removed it and isolated it to a service.

Then in my service I try to check/set/edit my cookies:

import { Cookie } from 'ng2-cookies'
//.. other imports

// ... code ...

@Injectable()
export class SiteSearchService {
    // ...code .. constructor, etc

    search(term: string) {
         if(!Cookie.check('cookie-name')) {
            Cookie.set('cookie-name', term)
         }
    }
}

It seems to be working now after I cleared node_modules and reinstalled via yarn. I think it was an issue when installing it the first time.