Chuyển đến nội dung chính

Bài đăng

Đang hiển thị bài đăng từ Tháng 10, 2021

Angular: Toast Notification

Hiển thị thông báo và cảnh báo là một trong những tính năng cần thiết cho website. Trong bài viết này, mình hướng dẫn các bạn tích hợp Toast Notification vào hệ thông. Toast là một popup thông báo, được hiển thị cho người dùng với nội dung tin nhắn có thể đọc được ở cuối màn hình hoặc tại một vị trí cụ thể và tự động biến mất sau vài giây. Cài đặt npm install ngx-toastr --save npm install @angular/animations --save Thiết lập Mở file angular.json, thêm toastr.css như sau: "styles": [ "styles.scss", "node_modules/ngx-toastr/toastr.css" // try adding '../' if you're using angular cli before 6 ] Mở file app.module.ts, thêm BrowserAnimationsModule, ToastrModule: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ToastrModule } f

RxJS : of, tap, map, và filter

Trong bài viết này, mình cố gắng tổng hợp và đưa ra các ví dụ đơn giản về các hàm of(), tap(), map(), và filter(). of() of(...items)—Returns an Observable instance that synchronously delivers the values provided as arguments.  Trả về 1 biến observable // Create simple observable that emits three values const myObservable = of(1, 2, 3); // Create observer object const myObserver = { next: (x: number) => console.log('Observer got a next value: ' + x), error: (err: Error) => console.error('Observer got an error: ' + err), complete: () => console.log('Observer got a complete notification'), }; // Execute with the observer object myObservable.subscribe(myObserver); // Logs: // Observer got a next value: 1 // Observer got a next value: 2 // Observer got a next value: 3 // Observer got a complete notification tap() RxJS tap performs side effects for every value emitted by source Observable and returns an Observable identical to the source Observabl