Angular2:从子组件向父组件发送多个事件

Angular2: Send more than one event from child to parent component

我发送一个这样的事件用于删除

<child-component *ngFor = "#todo of array" [taskobject] = "todo" 
(childevent) = "deleteparent($event)">Loading...</child-component>

我怎样才能将另一个事件与儿童事件一起发送,是否以逗号分隔?像这样?

<child-component *ngFor = "#todo of array" [taskobject] = "todo" 
(childevent) = "deleteparent($event)", 
(updateevent)> = "(updateparent)"Loading...</child-component>

同样对于edit/update请求我应该向服务器请求什么http,是不是http.put也是在服务器端,是server.put('url')吗?

更新:

<child-component *ngFor = "#todo of array" 
[taskobject] = "todo"   (childevent) = "deleteparent($event)"
; (updatevent) = "updateparent($event)">Loading...</child-component>

请试试

(childevent)="deleteparent($event);updateparent($event)"

我认为您想在同一元素上处理多个事件。如果是这样,请列出以 space 分隔的事件处理程序,就像使用常规 HTML 属性一样:

<child-component *ngFor = "#todo of array" [taskobject] = "todo" 
   (childevent) = "deleteparent($event)" 
   (updateevent) = "updateparent($event)">Loading...</child-component>

你应该用 ; 将它们分开,但条件是如果第一个表达式出错,它不会计算下一个表达式。但在你的情况下,这两个都是函数,所以它会 运行 正如预期的那样:

(anyevent)="function1($event);function2($event);etc"

这也适用于 && 符号,如下所示:

(anyevent)="function1($event)&&function2($event);etc"

尝试 it.hope 这可能对您有所帮助。