Skip to content

Commit ef787ad

Browse files
committed
Add fetch resources
1 parent 4e51058 commit ef787ad

12 files changed

Lines changed: 126 additions & 19 deletions

package-lock.json

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@angular/router": "~8.2.11",
2626
"@nodegui/nodegui": "^0.2.1",
2727
"core-js": "^3.3.2",
28+
"node-fetch": "^2.6.0",
2829
"rxjs": "~6.4.0",
2930
"tslib": "^1.10.0",
3031
"zone.js": "^0.9.1"

src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
[value]="20"
2626
>
2727
</spinbox>
28+
<app-hello [name]="'irustm'"></app-hello>
2829
</view>
2930
</window>

src/app/app.component.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#app {
2+
background-color: gray;
3+
}
4+
5+
#app-hello {
6+
background-color: green;
7+
}

src/app/app.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import { AspectRatioMode } from '@nodegui/nodegui';
44
@Component({
55
selector: 'app-root',
66
templateUrl: './app.component.html',
7-
styles: [
8-
`
9-
#app {
10-
background-color: gray;
11-
}
12-
#button {
13-
}
14-
`
15-
],
7+
styleUrls: ['./app.component.scss'],
168
encapsulation: ViewEncapsulation.None
179
})
1810
export class AppComponent {

src/app/app.module.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { HttpClientModule, HttpClient } from '@angular/common/http';
23

34
import { AppComponent } from './app.component';
45
import { NodeguiLibModule } from '../lib/nodegui-lib.module';
6+
import { HelloComponent } from './hello/hello.component';
7+
import { GithubService } from './github.service';
8+
import { HttpFetchBackend } from '../lib/http-fetch-backend';
59

610
@NgModule({
7-
declarations: [AppComponent],
8-
imports: [NodeguiLibModule],
9-
providers: [],
11+
declarations: [AppComponent, HelloComponent],
12+
imports: [NodeguiLibModule, HttpClientModule],
13+
providers: [
14+
GithubService,
15+
{
16+
provide: HttpClient,
17+
useFactory: () => new HttpClient(new HttpFetchBackend())
18+
}
19+
],
1020
bootstrap: [AppComponent],
1121
schemas: [NO_ERRORS_SCHEMA]
1222
})

src/app/github.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
4+
const API_URL = 'https://api.github.com';
5+
6+
@Injectable({
7+
providedIn: 'root'
8+
})
9+
export class GithubService {
10+
constructor(private http: HttpClient) {}
11+
12+
getUser(username: string) {
13+
return this.http.get(`${API_URL}/users/${username}`);
14+
}
15+
}

src/app/hello/hello.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<view>
2+
<text>{{ avatarUrl }}</text>
3+
</view>

src/app/hello/hello.component.scss

Whitespace-only changes.

src/app/hello/hello.component.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
Component,
3+
OnInit,
4+
ViewEncapsulation,
5+
Input,
6+
OnDestroy
7+
} from '@angular/core';
8+
import { GithubService } from '../github.service';
9+
import { Subscription } from 'rxjs';
10+
11+
@Component({
12+
selector: 'app-hello',
13+
templateUrl: './hello.component.html',
14+
styleUrls: ['./hello.component.scss'],
15+
encapsulation: ViewEncapsulation.None
16+
})
17+
export class HelloComponent implements OnInit, OnDestroy {
18+
@Input() name;
19+
20+
public avatarUrl: string;
21+
22+
private subscribtion: Subscription;
23+
24+
constructor(private github: GithubService) {}
25+
26+
ngOnInit(): void {
27+
this.subscribtion = this.github
28+
.getUser(this.name)
29+
.subscribe((data: any) => {
30+
console.log(data);
31+
this.avatarUrl = data.avatar_url;
32+
});
33+
}
34+
35+
ngOnDestroy(): void {
36+
this.subscribtion.unsubscribe();
37+
}
38+
}

0 commit comments

Comments
 (0)