2016-02-13 60 views
0

林发送一个事件像这样删除Angular2:从孩子送到一个以上的事件父组件

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

我怎么能一起发送的另一事件与childevent,是逗号seprated?喜欢这个?

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

还为编辑/更新请求HTTP什么,我应该请求服务器,是它也http.put在服务器端,是server.put(“URL”)?

更新:

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

用分号';'分隔的几个表达式应该可以工作。不明白'htt.put'或'server.put('url')'是什么意思。 –

+0

其例如,http.delete在客户端,server.get()在服务器端,即时通讯todo应用程序 – blackHawk

+0

https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods –

回答

1

我认为要处理同一元素对多个事件。如果是这样,请列出由空格分隔的事件处理程序,就像你用普通的HTML属性:

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

http请求和服务器端的编辑?它是http.put()和服务器端express-server.put()? – blackHawk

+0

@blackHawk取决于服务器上实现的内容,但最佳做法是使用HTTP方法来设计他们的目标: GET - 获取资源 POST - 创建新资源 PUT - 更新资源 DELETE - 删除资源还有一些其他的方法,但是这四个是最常用的 –

0

请尝试,而不是

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

你应该将它们与;分开,但条件是如果第一个表达式不顺心,就不会评价一个表达式。但在这里,你的情况都是这样的功能如预期它会运行:

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

这也与&&符号的工作是这样的:

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

尝试it.hope这可能会帮助你。

相关问题