简体   繁体   English

如何使用另一个组件中一个组件的表单

[英]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.

相关问题 如何将参数从一个组件传递到另一组件 - How to pass parameter from one component to another 从另一个不同的AngularJS组件访问表单(用于验证) - Access a form (for validation) from another a different AngularJS component angularjs中另一种表单内的表单组件 - form component inside another form in angularjs 如何使用angular 1.x服务从一个组件更新另一个组件? - How to use angular 1.x services to update one component from another? 如何在组件模板中使用组件的 insideHTML? - How to use component's insideHTML in the component template? 如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据 - how to bind the new values to array variable from one component to another component along with existing data's in first component 如何从angular 1.5组件获取表单验证 - how to get form validation from angular 1.5 component 如何在ng-forward中将函数回调从一个组件传递到另一组件 - How to pass function callback from one component to another component in ng-forward Angular 2:如何从代码中动态加载另一个组件内的组件控件 - Angular 2 : How to dynamically load component control inside another component from code 如何在angular2的另一个组件中显示功能中的数据? - how to display data from function in another component in angular2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM