Angular 2 - bigktmbig/MyExperienceAlgorithm GitHub Wiki

================================================ cú pháp ở html

  • (): dành cho các sự kiện: change, click, blur,... <input (change)="Update()" />
  • []: binding 1 chiều : thay đổi value của input bằng biến inpvalue:// <input [value]="inpValue" />
  • [()]: binding 2 chiều : thay đổi value của input bằng biến inpvalue:// <input [(ngModel)]="inpValue" />
  • *: dùng cho câu điều kiện :If, For, ...:// <div *ngFor="let item of items" /> ===================================================2019/07/10 validate match password import { FormGroup } from '@angular/forms';

// custom validator to check that two fields match export function MustMatch(controlName: string, matchingControlName: string) { return (formGroup: FormGroup) => { const control = formGroup.controls[controlName]; const matchingControl = formGroup.controls[matchingControlName];

    if (matchingControl.errors && !matchingControl.errors.mustMatch) {
        // return if another validator has already found an error on the matchingControl
        return;
    }

    // set error on matchingControl if validation fails
    if (control.value !== matchingControl.value) {
        matchingControl.setErrors({ mustMatch: true });
    } else {
        matchingControl.setErrors(null);
    }
}

} ====================================================2019/07/12 use Fetch, httpClient, axios

  • httpClient: constructor(private http: HttpClient) { const data = http.get('https://jsonplaceholder.typicode.com/todos/1'); // Subscribe to begin listening for async result data.subscribe((data: Config) =>{

        console.log(data);
    });
    

    }

  • Fetch: constructor() { const data = from(fetch('https://jsonplaceholder.typicode.com/todos/1')); // Subscribe to begin listening for async result data.subscribe({ next(response) { response.json().then(function(data) { console.log(data); }); }, error(err) { console.error('Error: ' + err); }, complete() { console.log('Completed'); } }); }

===================================================2019/07/12 singleton, multi thread

    1. singleton: public class LazyInitializedSingleton {

    private static LazyInitializedSingleton instance;

    private LazyInitializedSingleton(){}

    public static LazyInitializedSingleton getInstance(){ if(instance == null){ instance = new LazyInitializedSingleton(); } return instance; } }

    1. Multi Thread: public class ThreadSafeSingleton { private static ThreadSafeSingleton instance; private ThreadSafeSingleton(){}

    public static ThreadSafeSingleton getInstance(){ if(instance == null){ synchronized(ThreadSafeSingleton.class){ if(instance == null){ instance = new ThreadSafeSingleton(); } } } return instance; } }