[英]How to use a form from a component in another component
I have a form controller and a table controller, in my table I have a edit button, when I clicked this button my pop need to show up and update my user in table. 我有一个表单控制器和一个表控制器,在我的表中有一个编辑按钮,当我单击此按钮时,我的弹出窗口需要显示并更新表中的用户。 How I do this?
我该怎么做? How I use form from his component in my table component?
如何在他的表格组件中使用他的组件中的表格?
What you are looking for is a way of passing data between controllers (Table Controller and the Form Controller). 您正在寻找的是一种在控制器(表控制器和表单控制器)之间传递数据的方法。 In this case, you need to introduce a service that keeps the value of the clicked item in your table list - this service should have both the "set" method and the "get" method.
在这种情况下,您需要引入一种将单击项的值保留在表列表中的服务-该服务应同时具有“设置”方法和“获取”方法。 Your Table Controller sets the value and your Form Controller can simply read the value and populate its fields according.
您的表控制器设置值,表单控制器可以简单地读取值并根据其填充字段。
Somewhere in your Table Controller: 表控制器中的某个位置:
$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");
};
Somewhere in your Form Controller: 在表单控制器中的某个位置:
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;
This is a fairly common use case for most applications - I have created a basic AngularJS project that demonstrates this - you can try and follow it and see if this. 对于大多数应用程序来说,这是一个相当普遍的用例-我创建了一个基本的AngularJS项目来演示这一点-您可以尝试并遵循它,看看是否可以这样做。 See my angularjs-list-details-tutorial .
参见我的angularjs-list-details-tutorial 。
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.