简体   繁体   English

为什么自定义管道不适用于 Angular 2 中的本地模板变量

[英]why Custom Pipe Doesn't work with local Template variables in Angular 2

I have a Pipe just for Example that Squares the value that it receives this below one works fine我有一个管道只是作为例子,它平方它收到的值低于一个工作正常

Template模板

<input type = "number" placeholder = "Enter number for which square is to be calculated" [(ngModel)] = "value">
  <p>Squared Number is using pipe Transform  {{value | square}} </p>

Component成分

value = 2;

Custom Pipe定制管

import { Pipe,PipeTransform } from '@angular/core';

@Pipe({
    name:'square'
})

export class SquarePipe implements PipeTransform{
  transform(value: number, args?: number[]): number {
    return Math.pow(value, 2);
  }

}

But when i try to use the template like this但是当我尝试使用这样的模板时

it doesn't work I need to know why ?它不起作用我需要知道为什么?

<input type = "number" placeholder = "Enter number for which square is to be calculated" #value>
  <p>Squared Number is using pipe Transform  {{value | square}} </p>

I guess what you want is我想你想要的是

<p>Squared Number is using pipe Transform  {{value.value | square}} </p>

value alone refers to the HTMLInputElement单独的value指的是HTMLInputElement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM