[英]How to use a form from a component in another component
我有一個表單控制器和一個表控制器,在我的表中有一個編輯按鈕,當我單擊此按鈕時,我的彈出窗口需要顯示並更新表中的用戶。 我該怎么做? 如何在他的表格組件中使用他的組件中的表格?
您正在尋找的是一種在控制器(表控制器和表單控制器)之間傳遞數據的方法。 在這種情況下,您需要引入一種將單擊項的值保留在表列表中的服務-該服務應同時具有“設置”方法和“獲取”方法。 您的表控制器設置值,表單控制器可以簡單地讀取值並根據其填充字段。
表控制器中的某個位置:
$scope.selectItem = function (item){
console.log("Selected Item ", item);
//we indicate to our ItemsService that this is the current item
ItemsService.setSelectedItem(item);
//switch to item-view form (which will then use the ItemsService to get the selected item)
$location.path("/form");
};
在表單控制器中的某個位置:
var selectedItem = ItemsService.getSelectedItem();
console.log("Got Item Selected From List :: ", selectedItem, "");
//this is how we load it on the "details form"
$scope.formData = selectedItem;
對於大多數應用程序來說,這是一個相當普遍的用例-我創建了一個基本的AngularJS項目來演示這一點-您可以嘗試並遵循它,看看是否可以這樣做。 參見我的angularjs-list-details-tutorial 。
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.