2016-02-13 59 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這可能會幫助你。

相關問題