Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit 9733603

Browse files
committed
Fixed change detection.
1 parent abb368b commit 9733603

File tree

10 files changed

+70
-46
lines changed

10 files changed

+70
-46
lines changed

src/contacts/contacts.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -13,10 +13,11 @@ export class ContactsComponent implements OnInit {
1313
private contacts = [];
1414

1515
constructor(private graph: GraphService,
16-
private toast: ToastComponent) {
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1718
}
1819

19-
ngOnInit(){
20+
public ngOnInit() {
2021
this.toast.show(USER_MESSAGES.get_contacts);
2122
this.getContacts();
2223
}
@@ -26,6 +27,7 @@ export class ContactsComponent implements OnInit {
2627
.then((data: any) => {
2728
if (data) {
2829
this.contacts = data.value;
30+
this.changeRef.detectChanges();
2931
} else {
3032
this.toast.show(USER_MESSAGES.fail_graph_api);
3133
}
@@ -34,4 +36,4 @@ export class ContactsComponent implements OnInit {
3436
this.toast.show(USER_MESSAGES.fail_graph_api);
3537
});
3638
}
37-
}
39+
}

src/files/files.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
99
selector: "my-files",
10-
templateUrl: "src/files/view-files.html"
10+
templateUrl: "src/files/view-files.html",
1111
})
1212

1313
export class FilesComponent implements OnInit {
14-
private files = [];
14+
private files;
1515

1616
constructor(private graph: GraphService,
17-
private toast: ToastComponent) {
17+
private toast: ToastComponent,
18+
private changeRef: ChangeDetectorRef) {
1819
}
1920

20-
ngOnInit() {
21+
public ngOnInit() {
2122
this.toast.show(USER_MESSAGES.get_files);
2223
this.getFiles();
2324
}
@@ -27,11 +28,12 @@ export class FilesComponent implements OnInit {
2728
.then((data: any) => {
2829
if (data) {
2930
this.files = data.value;
31+
this.changeRef.detectChanges();
3032
} else {
3133
this.toast.show(USER_MESSAGES.fail_graph_api);
3234
}
3335
}).catch(() => {
3436
this.toast.show(USER_MESSAGES.fail_graph_api);
3537
});
3638
}
37-
}
39+
}

src/files/view-files.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ <h3>My Files</h3>
1313
</tr>
1414
</thead>
1515
<tbody>
16-
<tr *ngFor="let file of files">
17-
<td></td>
16+
<tr *ngFor="let file of files; let i=index">
17+
<td>{{i + 1}}</td>
1818
<td class="mdl-data-table__cell--non-numeric">
1919
<span *ngIf="file.file">File</span>
2020
<span *ngIf="!file.file">Folder</span>

src/groups/groups.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -13,10 +13,11 @@ export class GroupsComponent implements OnInit {
1313
private groups = [];
1414

1515
constructor(public graph: GraphService,
16-
public toast: ToastComponent) {
16+
public toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1718
}
1819

19-
ngOnInit() {
20+
public ngOnInit() {
2021
this.toast.show(USER_MESSAGES.get_groups);
2122
this.getGroups();
2223
}
@@ -26,6 +27,7 @@ export class GroupsComponent implements OnInit {
2627
.then((data: any) => {
2728
if (data) {
2829
this.groups = data.value;
30+
this.changeRef.detectChanges();
2931
} else {
3032
this.toast.show(USER_MESSAGES.fail_graph_api);
3133
}
@@ -34,4 +36,4 @@ export class GroupsComponent implements OnInit {
3436
this.toast.show(USER_MESSAGES.fail_graph_api);
3537
});
3638
}
37-
}
39+
}

src/mails/mails.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -13,10 +13,11 @@ export class MailsComponent implements OnInit {
1313
private messages = [];
1414

1515
constructor(private graph: GraphService,
16-
private toast: ToastComponent) {
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1718
}
1819

19-
ngOnInit(){
20+
public ngOnInit() {
2021
this.toast.show(USER_MESSAGES.get_mails);
2122
this.getMails();
2223
}
@@ -26,6 +27,7 @@ export class MailsComponent implements OnInit {
2627
.then((data: any) => {
2728
if (data) {
2829
this.messages = data.value;
30+
this.changeRef.detectChanges();
2931
} else {
3032
this.toast.show(USER_MESSAGES.fail_graph_api);
3133
}
@@ -34,4 +36,4 @@ export class MailsComponent implements OnInit {
3436
this.toast.show(USER_MESSAGES.fail_graph_api);
3537
});
3638
}
37-
}
39+
}

src/notes/notes.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -12,10 +12,12 @@ import { OFFICE_URLS } from "../office/office-urls";
1212
export class NotesComponent implements OnInit {
1313
private books = [];
1414

15-
constructor(private graph: GraphService, private toast: ToastComponent) {
15+
constructor(private graph: GraphService,
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1618
}
1719

18-
ngOnInit(){
20+
public ngOnInit() {
1921
this.toast.show(USER_MESSAGES.get_notebooks);
2022
this.getNotebooks();
2123
}
@@ -25,6 +27,7 @@ export class NotesComponent implements OnInit {
2527
.then((data: any) => {
2628
if (data) {
2729
this.books = data.value;
30+
this.changeRef.detectChanges();
2831
} else {
2932
this.toast.show(USER_MESSAGES.fail_graph_api);
3033
}
@@ -33,4 +36,4 @@ export class NotesComponent implements OnInit {
3336
this.toast.show(USER_MESSAGES.fail_graph_api);
3437
});
3538
}
36-
}
39+
}

src/profile/profile.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Injectable } from "@angular/core";
1+
import { Component, OnInit, Injectable, ApplicationRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
@@ -14,7 +14,9 @@ export class ProfileComponent implements OnInit {
1414
private displayName: string = "User";
1515
private photo: string = "";
1616

17-
constructor(private graph: GraphService, private toast: ToastComponent) {
17+
constructor(private graph: GraphService,
18+
private toast: ToastComponent,
19+
private changeRef: ApplicationRef) {
1820
}
1921

2022
public ngOnInit() {
@@ -37,6 +39,7 @@ export class ProfileComponent implements OnInit {
3739
this.graph.getRequestPromise(OFFICE_URLS.me_profile_url).then((data: any) => {
3840
if (data) {
3941
this.displayName = data.displayName;
42+
this.changeRef.tick();
4043
} else {
4144
this.toast.show(USER_MESSAGES.fail_username);
4245
}
@@ -49,6 +52,7 @@ export class ProfileComponent implements OnInit {
4952
this.graph.getPhotoRequestPromise(OFFICE_URLS.me_photo_url).then((data: any) => {
5053
if (data) {
5154
this.photo = data;
55+
this.changeRef.tick();
5256
} else {
5357
this.toast.show(USER_MESSAGES.fail_user_photo);
5458
}

src/tasks/tasks.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -12,10 +12,12 @@ import { OFFICE_URLS } from "../office/office-urls";
1212
export class TasksComponent implements OnInit {
1313
private tasks = [];
1414

15-
constructor(private graph: GraphService, private toast: ToastComponent) {
15+
constructor(private graph: GraphService,
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1618
}
1719

18-
ngOnInit(){
20+
public ngOnInit() {
1921
this.toast.show(USER_MESSAGES.get_tasks);
2022
this.getTasks();
2123
}
@@ -25,6 +27,7 @@ export class TasksComponent implements OnInit {
2527
.then((data: any) => {
2628
if (data) {
2729
this.tasks = data.value;
30+
this.changeRef.detectChanges();
2831
} else {
2932
this.toast.show(USER_MESSAGES.fail_graph_api);
3033
}
@@ -33,4 +36,4 @@ export class TasksComponent implements OnInit {
3336
this.toast.show(USER_MESSAGES.fail_graph_api);
3437
});
3538
}
36-
}
39+
}

src/trending/trending.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -12,10 +12,12 @@ import { OFFICE_URLS } from "../office/office-urls";
1212
export class TrendingComponent implements OnInit {
1313
private trends = [];
1414

15-
constructor(private graph: GraphService, private toast: ToastComponent) {
15+
constructor(private graph: GraphService,
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1618
}
1719

18-
ngOnInit(){
20+
public ngOnInit() {
1921
this.toast.show(USER_MESSAGES.get_trending);
2022
this.getTrending();
2123
}
@@ -25,6 +27,7 @@ export class TrendingComponent implements OnInit {
2527
.then((data: any) => {
2628
if (data) {
2729
this.trends = data.value;
30+
this.changeRef.detectChanges();
2831
} else {
2932
this.toast.show(USER_MESSAGES.fail_graph_api);
3033
}
@@ -33,4 +36,4 @@ export class TrendingComponent implements OnInit {
3336
this.toast.show(USER_MESSAGES.fail_graph_api);
3437
});
3538
}
36-
}
39+
}

src/users/users.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
22

33
import { GraphService } from "../services/graph.service";
44
import { ToastComponent } from "../toast/toast.component";
5-
import { USER_MESSAGES } from "../messages/messages"
5+
import { USER_MESSAGES } from "../messages/messages";
66
import { OFFICE_URLS } from "../office/office-urls";
77

88
@Component({
@@ -12,10 +12,12 @@ import { OFFICE_URLS } from "../office/office-urls";
1212
export class UsersComponent implements OnInit {
1313
private users = [];
1414

15-
constructor(private graph: GraphService, private toast: ToastComponent) {
15+
constructor(private graph: GraphService,
16+
private toast: ToastComponent,
17+
private changeRef: ChangeDetectorRef) {
1618
}
1719

18-
ngOnInit(){
20+
public ngOnInit() {
1921
this.toast.show(USER_MESSAGES.get_users);
2022
this.getUsers();
2123
}
@@ -25,6 +27,7 @@ export class UsersComponent implements OnInit {
2527
.then((data: any) => {
2628
if (data) {
2729
this.users = data.value;
30+
this.changeRef.detectChanges();
2831
} else {
2932
this.toast.show(USER_MESSAGES.fail_graph_api)
3033
}
@@ -33,4 +36,4 @@ export class UsersComponent implements OnInit {
3336
this.toast.show(USER_MESSAGES.fail_graph_api)
3437
});
3538
}
36-
}
39+
}

0 commit comments

Comments
 (0)