Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom patterns not working with AOT compiler #290

Closed
asp-id opened this issue Jan 27, 2019 · 5 comments
Closed

Custom patterns not working with AOT compiler #290

asp-id opened this issue Jan 27, 2019 · 5 comments

Comments

@asp-id
Copy link

asp-id commented Jan 27, 2019

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.

@Thegrep01
Copy link
Contributor

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

@Phantoll
Copy link

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

bpopnikolov added a commit to bpopnikolov/ngx-mask that referenced this issue Apr 28, 2019
added factory support for options in forRoot(options) in order to
allow customPatterns support at root level with aot complition

fixes issue: JsDaddy#290
@bpopnikolov
Copy link
Contributor

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.

NepipenkoIgor pushed a commit that referenced this issue Apr 30, 2019
added factory support for options in forRoot(options) in order to
allow customPatterns support at root level with aot complition

fixes issue: #290
@NepipenkoIgor
Copy link
Collaborator

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

@xuxicheta
Copy link

xuxicheta commented Dec 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants