Angularjs 无法附加集合表单类型为Symfony2的ng模型

Angularjs 无法附加集合表单类型为Symfony2的ng模型,angularjs,Angularjs,我和Symfony2和AngularJs一起工作 我已经用jquery创建了一个表单集合,比如symfony2文档,并且我已经为动态创建的每个输入分配了ng模型,但是当我提交表单时,Angularjs Dom没有检测到创建的动态ng模型!! 我尝试了$compile和$apply,但没有结果 请帮忙 我的代码: <script> var $collectionHolder; // setup an "add a guest" link var $addGuestLink = $('

我和Symfony2和AngularJs一起工作

我已经用jquery创建了一个表单集合,比如symfony2文档,并且我已经为动态创建的每个输入分配了ng模型,但是当我提交表单时,Angularjs Dom没有检测到创建的动态ng模型!! 我尝试了$compile和$apply,但没有结果 请帮忙 我的代码:

<script>
var $collectionHolder;

// setup an "add a guest" link
var $addGuestLink = $('<a href="#" class="add_guest_link">Add a guest</a>');
var $newLinkLi = $('<li></li>').append($addGuestLink);

jQuery(document).ready(function () {
    // Get the ul that holds the collection of guests
    $collectionHolder = $('ul.guests');

    // add a delete link to all of the existing tag form li elements
    $collectionHolder.find('li').each(function () {
        addGuestFormDeleteLink($(this));
    });

    // add the "add a guest" anchor and li to the guests ul
    $collectionHolder.append($newLinkLi);

    // count the current form inputs we have (e.g. 2), use that as the new
    // index when inserting a new item (e.g. 2)
    $collectionHolder.data('index', $collectionHolder.find(':input').length);

    $addGuestLink.on('click', function (e) {
        // prevent the link from creating a "#" on the URL
        e.preventDefault();

        // add a new guest form (see next code block)
        addGuestForm($collectionHolder, $newLinkLi);
        var $scope = angular.element('#expenseCtrl').scope();

        $scope.apply(angular.element('#expenseCtrl')
                .injector().get('$compile')(addGuestForm($collectionHolder, $newLinkLi))('$scope'));
    });
});


function addGuestForm($collectionHolder, $newLinkLi) {
    // Get the data-prototype explained earlier
    var prototype = $collectionHolder.data('prototype');

    // get the new index
    var index = $collectionHolder.data('index');

    // Replace '__name__' in the prototype's HTML to
    // instead be a number based on how many items we have
    var newForm = prototype.replace(/__name__/g, index);

                    $collectionHolder.data('index', $collectionHolder.children().length);

                    // Display the form in the page in an li, before the "Add a guest" link li
                    var $newFormLi = $('<li></li>').append(newForm);
                    $newLinkLi.before($newFormLi);

                    // add a delete link to the new form
                    addGuestFormDeleteLink($newFormLi);
                }

                function addGuestFormDeleteLink($guestFormLi) {
                    var $removeFormA = $('<a href="#">delete this guest</a>');
                    $guestFormLi.append($removeFormA);

                    $removeFormA.on('click', function (e) {
                        // prevent the link from creating a "#" on the URL
                        e.preventDefault();

                        // remove the li for the guest form
                        $guestFormLi.remove();
                    });
                }

      </script> 

var$collectionHolder;
//设置“添加来宾”链接
变量$addGuestLink=$('');
变量$newLinkLi=$('
  • ).append($addGuestLink); jQuery(文档).ready(函数(){ //获取保存客人集合的ul $collectionHolder=$('ul.guests'); //向所有现有标记表单li元素添加删除链接 $collectionHolder.find('li')。每个(函数(){ addGuestFormDeleteLink($(this)); }); //将“AddaGuest”主播和li添加到guests ul $collectionHolder.append($newLinkLi); //计算我们当前的表单输入(例如2),将其用作新的表单输入 //插入新项目时的索引(例如2) $collectionHolder.data('index',$collectionHolder.find(':input').length); $addGuestLink.on('click',函数(e){ //阻止链接在URL上创建“#” e、 预防默认值(); //添加新的来宾表单(请参阅下一个代码块) addGuestForm($collectionHolder,$newLinkLi); var$scope=angular.element('#expenseCtrl').scope(); $scope.apply(angular.element(“#expenseCtrl”) .injector().get(“$compile”)(addGuestForm($collectionHolder,$newLinkLi))(“$scope”); }); }); 函数addGuestForm($collectionHolder,$newLinkLi){ //获取前面解释的数据原型 var prototype=$collectionHolder.data('prototype'); //获取新索引 var索引=$collectionHolder.data('index'); //将原型HTML中的“\uuuu name\uuuuuu”替换为 //取而代之的是一个基于我们拥有多少物品的数字 var newForm=prototype.replace(/\uuuuu name\uuuuu/g,索引); $collectionHolder.data('index',$collectionHolder.childrence().length); //在“添加来宾”链接之前,在一个li页面中显示表单 变量$newFormLi=$('
  • ')。追加(newForm); $newLinkLi.before($newFormLi); //向新表单添加删除链接 addGuestFormDeleteLink($newFormLi); } 函数addGuestFormDeleteLink($guestFormLi){ var$removeFormA=$(''); $guestFormLi.append($removeFormA); $removeFormA.on('click',函数(e){ //阻止链接在URL上创建“#” e、 预防默认值(); //删除来宾表单的li $guestFormLi.remove(); }); }

    您的问题与symfonyi无关。当我单击链接时,我已成功地将动态ng模型添加到DOM中,但未能从“删除”链接中删除它们