BCJTI / ng2-cookies

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

add CookieService #41

Closed sod closed 7 years ago

sod commented 7 years ago

Add CookieService to be used in dependency injection in angular

import {CookieService} from 'ng2-cookies';

@Component({
    providers: [CookieService]
})
class MyComponent {
    constructor(cookie: CookieService) {
        cookie.get('foo');
    }
}

So you are able to mock it in unit tests.

Old export still works so this PR doesn't break existing users workflow.

import {Cookie} from 'ng2-cookies';

Cookie.get('foo');
Bigous commented 7 years ago

Very nice approach.

@carcamano It's good to go to me!

mylifeandcode commented 7 years ago

I still can't inject this during unit tests. Are you sure you don't need to apply the @Injectable decorator to the CookieService class?