简体   繁体   English

angularjs-ng提交表单不能与动态生成的html一起使用

[英]angularjs - form ng-submit not working with dynamic generated form html

I want to generate multiple forms using "ng-repeat" and bind data to the form. 我想使用“ ng-repeat”生成多个表单并将数据绑定到该表单。 I have already generated the html using angular js directive, but the events are not firing on generated HTML. 我已经使用angular js指令生成了html,但是事件并未在生成的HTML上触发。 I think angular js not able to find that HTML into the loaded DOM. 我认为angular js无法将HTML加载到DOM中。

Here is my code on Plunker: 这是我在Plunker上的代码:

http://plnkr.co/edit/lJsCUqzd1R6xkq1CgXOM?p=preview http://plnkr.co/edit/lJsCUqzd1R6xkq1CgXOM?p=preview

After generating the HMTL, I want to submit the form by "ng-submit" directive. 生成HMTL后,我想通过“ ng-submit”指令提交表单。 I am using angular js version 1.4.1 and my custom directive is 我正在使用angular js版本1.4.1,我的自定义指令是

<div custom-form formfor="eng" formforid="1"></div>

Since you are using isolated scope in your directive, the directive does not have access to parent scope function directly. 由于您在指令中使用隔离范围,因此该指令无法直接访问父范围函数。 What you can do is to pass the reference of the function to call on submit to directive using syntax: 您可以做的是使用以下语法传递函数的引用以调用submit to指令:

 scope: {
      formfor: "@",
      formforid: "@",
      formFn:"&"
    },

Then you need to modify the directive usage to 然后,您需要将指令用法修改为

<div custom-form formfor="eng" formforid="1" form-fn="newsForm2()"></div>

The directive template and implementation also need to change. 指令模板和实现也需要更改。

See my plunkr here http://plnkr.co/edit/Z4tf0Jqi59S8nNLCmH6z?p=preview 在此处查看我的plunkr http://plnkr.co/edit/Z4tf0Jqi59S8nNLCmH6z?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM