javascript - Add directives using another directive in angular2 -


my problem create single directive called date-input can applied html input field.

within custom date-input, want add other directives other modules same input. example, using textmask found here https://github.com/text-mask/text-mask/tree/master/angular2

i not want apply custom masks on application, instead add own directive, apply inputs, , if needs changing, have change 1 directive, rather places have implemented code.

using textmask have number field, let alone unmask value upon setting ngmodel. not want copy code throughout site on components, these thought simple directive great.

html

<input type="text" class="form-control"         [(ngmodel)]="inputvalue" [textmask]="{mask: mask, guide: false}" /> 

my typescript

import { component, input, onchanges } '@angular/core';  import createnumbermask 'text-mask-addons/dist/createnumbermask.js';  export class numbercomponent {     mask = createnumbermask({                     prefix: '',                     suffix: '',                     decimallimit: 0                 });     inputvalue: string = '';      unmask(val) {         let value = val.replace(/\d+/g, '');          if (value == '') {             return null;         } else {             return +value;         }     } } 

i create simple directive called "number-input" add [textmask]="{mask: mask, guide: false}" input @ runtime.

can done?


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -