ng-error-message
Version:
Displays error messages when a form control is invalid avoiding the long list of tags for each error
238 lines (228 loc) • 8.13 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
typeof define === 'function' && define.amd ? define('ng-error-message', ['exports', '@angular/core'], factory) :
(factory((global['ng-error-message'] = {}),global.ng.core));
}(this, (function (exports,i0) { 'use strict';
/**
* @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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NgErrorMessageService.ctorParameters = function () {
return [
{ type: NgErrorMessageLoader }
];
};
/** @nocollapse */ NgErrorMessageService.ngInjectableDef = i0.defineInjectable({ factory: function NgErrorMessageService_Factory() { return new NgErrorMessageService(i0.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: i0.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: i0.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
*/
exports.NgErrorMessageService = NgErrorMessageService;
exports.NgErrorMessageLoader = NgErrorMessageLoader;
exports.NgErrorMessageLoaderService = NgErrorMessageLoaderService;
exports.NgErrorMessageModule = NgErrorMessageModule;
exports.ɵa = NgErrorMessagePipe;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ng-error-message.umd.js.map