> For the complete documentation index, see [llms.txt](https://angular-token.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angular-token.gitbook.io/docs/migrate-to-7.md).

# Migrate to Angular-Token 7.x

The library has been renamed to **Angular-Token** and now includes Http Interceptor support. Please follow the steps below to upgrade from older versions.

## 1. Install new NPM package

The name of the npm has been changed as well. Please uninstall the older package and install the new one.

```bash
npm uninstall angular2-token

npm install angular-token
```

## 2. Change imports

Change all imports form 'angular2-token' to 'angular-token'. The module, service and models imported have been renamed as well. Removing the '2' in each name should do the trick.

### Before:

```javascript
import { 
  Angular2TokenService,
  Angular2TokenModule,
  Angular2TokenOptions
  ...
} from 'angular2-token';
```

### After:

```javascript
import { 
  AngularTokenService,
  AngularTokenModule,
  AngularTokenOptions
  ...
} from 'angular-token';
```

## 3. Change from Service import to Module import

Import `AngularTokenModule` in your root module instead of providing `Angular2TokenService`. Also remove the `.init()` and provide the `Angular2TokenOptions` via the `.forRoot()` function.

### Before:

```javascript
// Root Module
@NgModule({
  imports:      [ ... ],
  declarations: [ ... ],
  providers:    [ Angular2TokenService ],
  bootstrap:    [ ... ]
})

// Root Component
constructor(private tokenService: Angular2TokenService) {
  this.tokenService.init();
}
```

### After:

```javascript
@NgModule({
  imports: [
    ...,
    HttpClientModule,
    AngularTokenModule.forRoot({
      ...
    })
  ],
  declarations: [ ... ],
  providers:    [ AngularTokenModule ],
  bootstrap:    [ ... ]
})
```

## 4. Update '.signIn()', '.register()' and '.resetPassword()' to use 'login' rather than 'email'.

To allow for more flexibility in the login, we changed the models to accept 'login' rather than 'email'.

### Before:

```javascript
constructor(private tokenService: Angular2TokenService) { }

this.tokenService.signIn({
    email:    'example@example.org',
    password: 'secretPassword'
}).subscribe(
    res =>      console.log(res),
    error =>    console.log(error)
);
```

### After:

```javascript
this.tokenService.signIn({
    login:    'example@example.org',
    password: 'secretPassword'
}).subscribe(
    res =>      console.log(res),
    error =>    console.log(error)
);
```

## 5. Use regular HttpClient calls

Replace all tokenService wrapper calls (get, post, put, delete, etc) with regular HttpClient calls.

### Before:

```javascript
constructor(private tokenService: Angular2TokenService) { }

this.tokenService.get('my-resource/1').subscribe(
  res =>    console.log(res),
  error =>  console.log(error)
);
```

### After:

```javascript
constructor(private http: HttpClient) { }

this.http.get('my-resource/1').subscribe(
  res =>    console.log(res),
  error =>  console.log(error)
);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://angular-token.gitbook.io/docs/migrate-to-7.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
