08 November 2018

Sử dụng từ khóa Static và Readonly trong Angular 2

import { Component } from '@angular/core';

@Component({
    selector: 'show-errors',
    template: `<div></div>`,
})
export class ShowErrorsComponent {

    private static readonly errorMessages = {
        'required': () => 'This field is required',
        'minlength': (params) => 'The min number of characters is ' + params.requiredLength,
        'maxlength': (params) => 'The max allowed number of characters is ' + params.requiredLength,
        'pattern': (params) => 'The required pattern is: ' + params.requiredPattern,
        'years': (params) => params.message
    };

    private getMessage(type: string, params: any) {
        return ShowErrorsComponent.errorMessages[type](params);
    }

}

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang