Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么自定义事件不需要与xxx.target.value一起使用;_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 为什么自定义事件不需要与xxx.target.value一起使用;

Javascript 为什么自定义事件不需要与xxx.target.value一起使用;,javascript,angular,typescript,Javascript,Angular,Typescript,我对Angular还不熟悉,只是一个关于定制事件的问题。对于普通事件绑定,我们有以下代码: <input class="form-control" (input)="selectedProduct=$event.target.value" /> 但对于自定义绑定,我看到了如下代码: <tr *ngFor="..." [pa-attr]="getProducts().length < 6 ? 'bg-success' : 'bg-warning'" (pa-categ

我对Angular还不熟悉,只是一个关于定制事件的问题。对于普通事件绑定,我们有以下代码:

<input class="form-control" (input)="selectedProduct=$event.target.value" />

但对于自定义绑定,我看到了如下代码:

<tr *ngFor="..." [pa-attr]="getProducts().length < 6 ? 'bg-success' : 'bg-warning'" (pa-category)="newProduct.category=$event">

那么为什么不是:

<tr ... (pa-category)="newProduct.category=$event.target.value">

自定义组件发出可被
$event

假设

这是自定义组件:

<input class="form-control" (input)="selectedProduct=$event.target.value" (blur)="onBlur()"/>


@Output() exampleOutput= new EventEmitter();

onBlur() {
    exampleOutput.emit(selectedProduct)
}

@Output()示例Output=neweventemitter();
onBlur(){
exampleOutput.emit(selectedProduct)
}

由于
exampleOutput
直接发送值,当您使用
(exampleOutput)=“test=$event”
时,test直接获取值

谢谢您的回答。因此,如果我希望自定义事件遵循与第一种情况相同的模式,那么,
exampleOutput.emit()
应该是什么呢,例如:
exampleOutput.emit({target:{value:selectedProduct}})