ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

Custom patterns not working with AOT compiler

Open asp-id opened this issue 7 years ago • 5 comments

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 avatar Jan 27 '19 14:01 asp-id

@asp-id It is an angular limitation, cause aot does not support RegExp in module imports

Thegrep01 avatar Apr 02 '19 15:04 Thegrep01

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

Phantoll avatar Apr 26 '19 09:04 Phantoll

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 avatar Apr 28 '19 18:04 bpopnikolov

@bpopnikolov Thanks . @asp-id @Phantoll you could try latest version. We will publish it today evening

NepipenkoIgor avatar Apr 30 '19 09:04 NepipenkoIgor

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

xuxicheta avatar Dec 20 '19 21:12 xuxicheta