如何将每个用户输入的“ 0”替换为“ 1”

时间:2019-12-13 08:00:53

标签: angular angular-directive

这是我的OnlyNumber指令,它只能在数字上正常工作。我希望每当用户在输入字段中输入0时,它将转换为1

<input OnlyNumber='true'  MaxNumber="9" type="text" [(ngModel)]='cart.selectedQty'
                                (ngModelChange)='calculateTotalPrice($event,cart,i)' class="mb-0" />

这是我的html输入字段:

use threads;
use Thread::Queue;
use threads::shared;

$count = 5; 
sub process
          {
             print "proccess started";
             return $count --;
           }


sub getWorkItems 
               {  
                 $n =&process;
                 return $n--;
               }
print "******************worker_count*********************\n";
 print $n;


     sub worker {
                  my $tid = threads->tid;
                  my( $Qwork, $Qresults ) = @_;
                  while( my $work = $Qwork->dequeue ) 
                       {  
                          sub result 
                               { my $i = threads->tid; 
                                  print "\nhello \n";
                                  print  "$i";
                                  print "\n"
                                }
                         &result;
                     $Qresults->enqueue();
                  }
              }

our $THREADS = 1;

my $Qwork = new Thread::Queue;
my $Qresults = new Thread::Queue;


## Create the pool of workers
my @pool = map
{
    threads->create( \&worker, $Qwork, $Qresults )

} 1 .. $THREADS;

## Get the work items (from somewhere)
## and queue them up for the workers

while( my $workItem = getWorkItems()  ) 
    {
      $Qwork->enqueue( $workItem );
     }

$Qwork->enqueue( (undef) x $THREADS );

for ( 1 .. $THREADS ) 
    {

    while( $Qresults->dequeue ) 
         {
         ## Do something with the result ##
          print "Request_proccessed";
          }

    }

## Clean up the threads
$_->join for @pool;

请给我任何解决方法。

1 个答案:

答案 0 :(得分:4)

您可以在每个function get<T>(obj: T, props: (keyof T)[] | keyof T): any { const toArray = coereceArray(props); return obj && toArray.reduce( (result, prop) => result == null ? undefined : result[prop] as any, obj ); } const result = get({ a: { b: 'hey' } }, ['a', 'b']); const result2 = get({ a: { b: 'hey' } }, 'a'); 事件之后简单地将每个“ 0”替换为“ 1”,对吗? 喜欢:

keydown

演示供您参考:https://stackblitz.com/edit/angular-fndxsq

我的@HostListener('keyup', ['$event']) onKeyUp(event) { this.el.nativeElement.value= this.el.nativeElement.value.replace('0', '1'); } 来源:How can I get jquery .val() AFTER keypress event?

有关keyup的更多信息:https://www.w3schools.com/jsref/jsref_replace.asp