ng-error-message
Version:
Displays error messages when a form control is invalid avoiding the long list of tags for each error
224 lines (216 loc) • 6.5 kB
JavaScript
import { Injectable, Pipe, NgModule, defineInjectable, inject } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Abstract class
* @abstract
*/
var /**
* Abstract class
* @abstract
*/
NgErrorMessageLoader = /** @class */ (function () {
function NgErrorMessageLoader() {
}
return NgErrorMessageLoader;
}());
/**
* Load the json file
*/
var /**
* Load the json file
*/
NgErrorMessageLoaderService = /** @class */ (function () {
function NgErrorMessageLoaderService(_http, _dictURl) {
this._http = _http;
this._dictURl = _dictURl;
}
/**
* Gets the dictionary json file
* @param dictUrl the Url of the errors dictionary
*/
/**
* Gets the dictionary json file
* @return {?}
*/
NgErrorMessageLoaderService.prototype.getDictionary = /**
* Gets the dictionary json file
* @return {?}
*/
function () {
if (!/.json$/.test(this._dictURl)) {
throw this._dictURl + " must be a json file";
}
return this._http.get(this._dictURl);
};
return NgErrorMessageLoaderService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Service for serving the errors dictionary
*/
var NgErrorMessageService = /** @class */ (function () {
function NgErrorMessageService(_loader) {
this._loader = _loader;
/**
* Contains the dictionary of errors
*/
this._errors = {};
}
Object.defineProperty(NgErrorMessageService.prototype, "errors", {
get: /**
* @return {?}
*/
function () {
return this._errors;
},
enumerable: true,
configurable: true
});
/**
* Loads the dictionary
*/
/**
* Loads the dictionary
* @return {?}
*/
NgErrorMessageService.prototype.load = /**
* Loads the dictionary
* @return {?}
*/
function () {
var _this = this;
this._loader.getDictionary().subscribe((/**
* @param {?} dict
* @return {?}
*/
function (dict) {
_this._errors = dict;
}));
};
NgErrorMessageService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NgErrorMessageService.ctorParameters = function () { return [
{ type: NgErrorMessageLoader }
]; };
/** @nocollapse */ NgErrorMessageService.ngInjectableDef = defineInjectable({ factory: function NgErrorMessageService_Factory() { return new NgErrorMessageService(inject(NgErrorMessageLoader)); }, token: NgErrorMessageService, providedIn: "root" });
return NgErrorMessageService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgErrorMessagePipe = /** @class */ (function () {
function NgErrorMessagePipe(_errorMessageSrv) {
this._errorMessageSrv = _errorMessageSrv;
/**
* Saves the untransformed message
*/
this._cachedCleanMessage = null;
/**
* Saves the transformed message
*/
this._cachedTransformedMessage = null;
}
/**
* @param {?} errors
* @param {?=} args
* @return {?}
*/
NgErrorMessagePipe.prototype.transform = /**
* @param {?} errors
* @param {?=} args
* @return {?}
*/
function (errors, args) {
if (args === void 0) { args = {}; }
if (!errors || typeof errors !== 'object' || Array.isArray(errors) || typeof args !== 'object' || Array.isArray(args))
return null;
/** @type {?} */
var errKey = Object.keys(errors)[0];
// The first found error
/** @type {?} */
var errArgs = args[errKey];
/** @type {?} */
var msg = errKey !== undefined && this._errorMessageSrv.errors[errKey] || null;
if (this._cachedCleanMessage === msg) {
return this._cachedTransformedMessage;
}
this._cachedCleanMessage = msg;
if (msg) {
for (var p in errArgs) {
msg = msg.replace(new RegExp("{{\\s?" + p + "\\s?}}", 'g'), errArgs[p]);
}
}
this._cachedTransformedMessage = msg;
return msg;
};
NgErrorMessagePipe.decorators = [
{ type: Pipe, args: [{
name: 'errorMessage',
pure: false
},] }
];
/** @nocollapse */
NgErrorMessagePipe.ctorParameters = function () { return [
{ type: NgErrorMessageService }
]; };
return NgErrorMessagePipe;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgErrorMessageModule = /** @class */ (function () {
function NgErrorMessageModule() {
}
/**
* starts the services
* @param dictUrl The errors dictionary Url
*/
/**
* starts the services
* @param {?} jsonProvider
* @return {?}
*/
NgErrorMessageModule.forRoot = /**
* starts the services
* @param {?} jsonProvider
* @return {?}
*/
function (jsonProvider) {
return {
ngModule: NgErrorMessageModule,
providers: [
jsonProvider,
NgErrorMessageService
]
};
};
NgErrorMessageModule.decorators = [
{ type: NgModule, args: [{
declarations: [NgErrorMessagePipe],
exports: [NgErrorMessagePipe]
},] }
];
return NgErrorMessageModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NgErrorMessageService, NgErrorMessageLoader, NgErrorMessageLoaderService, NgErrorMessageModule, NgErrorMessagePipe as ɵa };
//# sourceMappingURL=ng-error-message.js.map