Custom patterns not working with AOT compiler
ngx-mask version - 7.3.3 angular version - 7
NgModule configuration
NgxMaskModule.forRoot({
patterns: {
'Z': {pattern: new RegExp('\[0-9a-zA-Z\]')}
}
})
Usage in html template
<input matInput="" formControlName="applicationNumber" mask="Z{20}"/>
When compile with --aot flag (ng serve -o --aot) mask not working. User can not enter any symbols. Unfortunately AOT compiler using by default for production mode, so custom patterns functionality is broken in prod.
@asp-id It is an angular limitation, cause aot does not support RegExp in module imports
as seeing here -> angulartics/angulartics2#339 it's a workarount to write it as string instand of creating a RegExp class instance - thats working for me
Since angular's collector supports only a sub-set of javascript providing a plain object with RegExp is not really gonna work. One way around this would be to provide a factory function which returns options object of type IConfig. This PR (#447 ) adds a support for factory function which will allow providing custormPatterns at root level.
@bpopnikolov Thanks . @asp-id @Phantoll you could try latest version. We will publish it today evening
Still not working Here is example https://github.com/xuxicheta/nxg-mask-prod-failure I've solved this by using function into forRoot parameter
export function NgxMaskConfig() {
return {
patterns: {
...initialConfig.patterns,
'Я': {
pattern: new RegExp('[А-Яа-я]'),
},
}
};
}
Well, it will be nice if its mention it in documentation