Skip to content

Commit 7e37992

Browse files
committed
replacing ng2-toastr with ngx-toastr
1 parent 9ee2e6a commit 7e37992

File tree

9 files changed

+52
-41
lines changed

9 files changed

+52
-41
lines changed

package-lock.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/angular/.angular-cli.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"prefix": "app",
2121
"styles": [
2222
"assets/vendor.scss",
23-
"assets/main.scss",
24-
"../node_modules/ng2-toastr/ng2-toastr.css"
23+
"assets/main.scss"
2524
],
2625
"scripts": [],
2726
"environmentSource": "environments/environment.ts",

src/angular/package-lock.json

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

src/angular/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"@ngrx/store-devtools": "^5.2.0",
3131
"bootstrap": "^4.1.1",
3232
"core-js": "^2.5.5",
33-
"ng2-toastr": "^4.1.2",
34-
"ngrx-data": "^1.0.0-beta.11",
33+
"ngrx-data": "^1.0.0-beta.13",
34+
"ngx-toastr": "^8.4.0",
3535
"rxjs": "^5.5.10",
3636
"zone.js": "^0.8.19"
3737
},

src/angular/src/app/app.component.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,29 @@ <h5 class="card-title">Welcome to {{ title }}</h5>
5252
Todo List with SpringBoot backend and Rest API, NgRx Data store solution for CRUD operations
5353
</p>
5454
</div>
55-
<ul class="list-group list-group-flush">
56-
<li *ngFor="let todo of todos$ | async; let i = index" class="list-group-item"><span [innerText]="todo.title"></span>
57-
<button class="float-right btn btn-sm btn-danger" (click)="deleteTodo(todo.id)">
58-
<i class="fas fa-trash"></i>
59-
</button>
60-
<button class="float-right btn btn-sm mr-2" [ngClass]="{'btn-secondary': !todo.active, 'btn-info': todo.active}" (click)="updateTodo(todo)">
61-
<span *ngIf="todo.active"><i class="far fa-check-square fa-lg"></i></span>
62-
<span *ngIf="!todo.active"><i class="far fa-square fa-lg"></i></span>
63-
</button>
64-
65-
</li>
66-
67-
</ul>
55+
<table class="table table-hover table-bordered">
56+
<thead class="thead-light">
57+
<tr>
58+
<th scope="col">#</th>
59+
<th scope="col">Title</th>
60+
<th>&nbsp;</th>
61+
</tr>
62+
</thead>
63+
<tbody>
64+
<tr *ngFor="let todo of todos$ | async; let i = index">
65+
<th scope="row"><span [innerText]="todo.id"></span></th>
66+
<td><span [innerText]="todo.title"></span></td>
67+
<td>
68+
69+
<i class="fas fa-trash float-right text-danger" (click)="deleteTodo(todo.id)"></i>
70+
<span *ngIf="todo.active"><i class="float-right far fa-check-square fa-lg text-info mr-2" (click)="updateTodo(todo)"></i></span>
71+
<span *ngIf="!todo.active"><i class="float-right far fa-square fa-lg text-secondary mr-2" (click)="updateTodo(todo)"></i></span>
72+
73+
</td>
74+
</tr>
75+
76+
</tbody>
77+
</table>
6878
</div>
6979

7080
<div class="alert alert-info mt-2">

src/angular/src/app/app.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { TodosService } from './services/todos.service';
44
import { Todo } from './dto/todo';
55
import { Observable } from 'rxjs/Observable';
66
import {ToastService} from "./services/toast.service";
7-
import {ToastsManager} from "ng2-toastr";
87

98
@Component({
109
selector: 'app-root',
@@ -23,19 +22,15 @@ export class AppComponent implements OnInit {
2322

2423
constructor(
2524
private todosService: TodosService,
26-
private toastService: ToastService,
27-
private toastr: ToastsManager,
28-
vcr: ViewContainerRef
25+
private toastService: ToastService
2926
) {
3027
this.todos$ = todosService.entities$;
31-
this.toastr.setRootViewContainerRef(vcr);
3228
}
3329
getTodos() {
3430
this.todosService.getAll();
3531
}
3632

3733
ngOnInit() {
38-
3934
this.yearNow = new Date().getFullYear().toString();
4035
this.appVersion = 'V X.X.X';
4136
this.getTodos();

src/angular/src/app/app.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33
import { HttpClientModule } from '@angular/common/http';
4-
import {ToastModule} from 'ng2-toastr/ng2-toastr';
54

65
import { AppComponent } from './app.component';
76
import { AppStoreModule } from './store/app-store.module';
@@ -10,9 +9,10 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
109
import { CounterComponent } from './counter/counter.component';
1110
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
1211
import { CountervalidComponent } from './counter/countervalid/countervalid.component';
13-
import {NoopAnimationsModule} from "@angular/platform-browser/animations";
12+
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
1413
import {CompModule} from "./comp/comp.module";
1514
import {DirectivesModule} from "./directives/directives.module";
15+
import {ToastrModule} from "ngx-toastr";
1616

1717

1818
@NgModule({
@@ -24,15 +24,15 @@ import {DirectivesModule} from "./directives/directives.module";
2424
imports: [
2525
DirectivesModule,
2626
CompModule,
27-
NoopAnimationsModule,
2827
FormsModule,
2928
ReactiveFormsModule,
3029
HttpClientModule,
3130
BrowserModule,
3231
AppStoreModule,
3332
ServicesModule,
3433
NgbModule.forRoot(),
35-
ToastModule.forRoot()
34+
BrowserAnimationsModule, // required animations module
35+
ToastrModule.forRoot(), // ToastrModule added
3636
],
3737
providers: [],
3838
bootstrap: [AppComponent]

src/angular/src/app/services/toast.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { Injectable } from '@angular/core';
22
import { EntityActions, OP_ERROR, OP_SUCCESS } from 'ngrx-data';
3-
import {ToastsManager} from "ng2-toastr";
3+
import {ToastrService} from "ngx-toastr";
44

55
@Injectable()
66
export class ToastService {
77

8-
constructor(actions$: EntityActions, public toastr: ToastsManager) {
8+
constructor(actions$: EntityActions, private toastrservice: ToastrService) {
99
actions$
1010
.where(ea => ea.op.endsWith(OP_SUCCESS) || ea.op.endsWith(OP_ERROR))
1111
// this service never dies so no need to unsubscribe
1212
.subscribe(action =>
13-
this.toastr.success(`${action.entityName} action`, 'Success!')
13+
// this is a hack against "expression changed" bug listed here https://github.com/scttcper/ngx-toastr/issues/160
14+
setTimeout(() => this.toastrservice.success(`${action.entityName} action`, 'Success!'))
1415
);
1516
}
1617

src/angular/src/assets/vendor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@import "variables";
22
@import "~bootstrap/scss/bootstrap";
3+
4+
/**
5+
ngx-toastr
6+
*/
7+
@import "~ngx-toastr/toastr-bs4-alert";
8+
39
/**
410
Font Awesome 5
511
*/

0 commit comments

Comments
 (0)