Skip to content

Commit 152aec5

Browse files
committed
Add github service
1 parent 22308d8 commit 152aec5

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/app/app.component.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
[src]="'C:/temp/angular.png'"
66
[aspectRatioMode]="aspectRatioMode"
77
></image>
8-
<text [style.font-size.px]="45">Hello, {{ name }}</text>
9-
<checkbox [checked]="true"></checkbox>
10-
<checkbox [checked]="true" [enabled]="false"></checkbox>
11-
<button [style.background-color]="'green'" (clicked)="setName()">
12-
Green button
13-
</button>
8+
9+
<app-hello [name]="name"></app-hello>
10+
11+
<text>Github name</text>
1412
<linedit
1513
[text]="name"
16-
[placeholderText]="'Insert your name'"
14+
[placeholderText]="'Insert github username'"
1715
(textChanged)="textChanged($event)"
1816
></linedit>
17+
18+
<!-- <checkbox [checked]="true"></checkbox>
19+
<checkbox [checked]="true" [enabled]="false"></checkbox>
20+
<button [style.background-color]="'green'" (clicked)="setName()">
21+
Green button
22+
</button>
23+
1924
<progressbar [value]="40" [minimum]="0" [maximum]="100"></progressbar>
2025
<spinbox
2126
[prefix]="'aa'"
@@ -24,7 +29,6 @@
2429
[range]="{ minimum: 0, maximum: 50 }"
2530
[value]="20"
2631
>
27-
</spinbox>
28-
<app-hello [name]="'irustm'"></app-hello>
32+
</spinbox> -->
2933
</view>
3034
</window>

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AspectRatioMode } from '@nodegui/nodegui';
88
encapsulation: ViewEncapsulation.None
99
})
1010
export class AppComponent {
11-
public name = 'World!';
11+
public name = 'irustm';
1212
public aspectRatioMode = AspectRatioMode.KeepAspectRatio;
1313

1414
setName() {

src/app/hello/hello.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<view>
2-
<text>{{ userName }}</text>
2+
<text [style.font-size.px]="45">Hello, {{ name }}</text>
33
</view>

src/app/hello/hello.component.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ import { Subscription } from 'rxjs';
1515
encapsulation: ViewEncapsulation.None
1616
})
1717
export class HelloComponent implements OnInit, OnDestroy {
18-
@Input() name;
18+
@Input() set name(value) {
19+
this.getUsername(value);
20+
}
1921

2022
public userName: string;
2123

2224
private subscribtion: Subscription;
2325

2426
constructor(private github: GithubService) {}
2527

26-
ngOnInit(): void {
27-
this.subscribtion = this.github
28-
.getUser(this.name)
29-
.subscribe((data: any) => {
30-
this.userName = data.name;
31-
});
28+
ngOnInit(): void {}
29+
30+
private getUsername(username: string) {
31+
if (this.subscribtion) {
32+
this.subscribtion.unsubscribe();
33+
}
34+
35+
this.subscribtion = this.github.getUser(username).subscribe((data: any) => {
36+
this.userName = data.name;
37+
});
3238
}
3339

3440
ngOnDestroy(): void {

0 commit comments

Comments
 (0)