Skip to content

Commit d2e0dec

Browse files
authored
Merge pull request #202 from mpalourdio/standalone
Standalone component support
2 parents 9045870 + 05aec32 commit d2e0dec

31 files changed

+1726
-474
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v16.1.0
4+
- Add full standalone components support.
5+
- Deprecate `NgHttpLoaderModule` and `forRoot`.
6+
- `PendingRequestsInterceptor` has been refactored from `class` to `function`.
7+
- Needed`getters` and `setters` have been extracted in a new `PendingRequestsInterceptorConfigurer`. If you had injected `PendingRequestsInterceptor` somewhere, you must switch to `PendingRequestsInterceptorConfigurer`. This is a needed BC break.
8+
- Note that `^16.0.0` is the last release supporting `NgModule`.
9+
- This is not semver compliant, I agree. But the direct usage of `PendingRequestsInterceptor` must be **very** low.
10+
311
## v16.0.0
412
- Added angular 18 support.
513

README.md

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,46 +51,29 @@ If you experience errors like below, **please double-check the version you use.*
5151

5252
`ERROR in Error: Metadata version mismatch for module [...]/angular/node_modules/ng-http-loader/ng-http-loader.module.d.ts, found version x, expected y [...]`
5353

54-
## Requirements - HttpClientModule
54+
## Requirements - HttpClient
5555

56-
Performing HTTP requests with the `HttpClientModule` API is **mandatory**. Otherwise, the spinner will not be fired **at all**.
57-
58-
See this [blog post](http://blog.ninja-squad.com/2017/07/17/http-client-module/) for an `HttpClientModule` introduction.
56+
Performing HTTP requests with the `HttpClient` API is **mandatory**. Otherwise, the spinner will not be fired **at all**.
5957

6058
## Usage
6159

62-
From your Angular `AppModule`:
60+
From your Angular root component (`app.component.ts` for example):
6361

6462
```typescript
65-
import { BrowserModule } from '@angular/platform-browser';
66-
import { NgModule } from '@angular/core';
67-
// [...]
68-
import { AppComponent } from './app.component';
69-
import { HttpClientModule } from '@angular/common/http'; // <============
70-
import { NgHttpLoaderModule } from 'ng-http-loader'; // <============
71-
72-
@NgModule({
73-
declarations: [
74-
AppComponent
75-
],
76-
imports: [
77-
BrowserModule,
78-
HttpClientModule, // <============ (Perform HTTP requests with this module)
79-
NgHttpLoaderModule.forRoot(), // <============ Don't forget to call 'forRoot()'!
80-
],
81-
providers: [],
82-
bootstrap: [AppComponent]
63+
@Component({
64+
selector: 'app-root',
65+
standalone: true,
66+
templateUrl: './app.component.html',
67+
styleUrls: ['./app.component.scss'],
68+
imports: [NgHttpLoaderComponent] <====== import the component
8369
})
84-
export class AppModule { }
8570
```
8671

87-
In your app.component.html, simply add:
72+
In your `app.component.html`, simply add:
8873
```xml
8974
<ng-http-loader></ng-http-loader>
9075
```
91-
## Standalone components
92-
93-
If you prefer using standalone components, you should configure your `ApplicationConfig` like following:
76+
At last, configure your `ApplicationConfig` like following:
9477

9578
```typescript
9679
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
@@ -102,30 +85,11 @@ import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
10285
export const appConfig: ApplicationConfig = {
10386
providers: [
10487
provideRouter(routes),
105-
provideHttpClient(
106-
withInterceptorsFromDi() // <== Don't forget to import the interceptors
107-
),
108-
importProvidersFrom(NgHttpLoaderModule.forRoot()) //<== Always call `forRoot`
88+
withInterceptors([pendingRequestsInterceptor$])
10989
],
11090
};
11191
```
112-
Then you can use `ng-http-loader` like this:
113-
```typescript
114-
import { Component } from '@angular/core';
115-
import {NgHttpLoaderModule} from "ng-http-loader";
11692

117-
@Component({
118-
selector: 'my-selector',
119-
standalone: true,
120-
imports: [
121-
NgHttpLoaderModule
122-
],
123-
template: `
124-
<ng-http-loader />`,
125-
})
126-
export class InlineComponent {
127-
}
128-
```
12993
## Customizing the spinner
13094

13195
You can customize the following parameters:
@@ -159,8 +123,10 @@ import { Spinkit } from 'ng-http-loader'; // <============
159123

160124
@Component({
161125
selector: 'app-root',
126+
standalone: true,
162127
templateUrl: './app.component.html',
163128
styleUrls: ['./app.component.css'],
129+
imports: [NgHttpLoaderComponent]
164130
})
165131
export class AppComponent {
166132
public spinkit = Spinkit; // <============
@@ -188,8 +154,10 @@ import { AwesomeComponent } from 'my.awesome.component';
188154

189155
@Component({
190156
selector: 'app-root',
157+
standalone: true,
191158
templateUrl: './app.component.html',
192-
styleUrls: ['./app.component.css']
159+
styleUrls: ['./app.component.css'],
160+
imports: [NgHttpLoaderComponent]
193161
})
194162
export class AppComponent {
195163
public awesomeComponent = AwesomeComponent;

0 commit comments

Comments
 (0)