简体   繁体   English

模态内的ng重复角度

[英]angular ng-repeat inside modal

I have a link which on clicking opens a modal. 我有一个链接,单击该链接会打开一个模式。 Am using angular ui modal. 我正在使用角度ui模态。 Inside modal I have a row with two inputs and an Add button. 在模态内部,我有一排带有两个输入和一个“添加”按钮。 On clicking Add button, a new row is added with the text I entered in inputs. 单击添加按钮后,将在新行中添加我在输入中输入的文本。 I have a done button which closes the modal. 我有一个完成的按钮,关闭模式。 On opening the modal again, my newly added row is missing. 再次打开模态时,我新添加的行丢失了。

Everytime you create a new Modal, you'll be running the code behind it again, effectively erasing any changes you make to it, even if you are using the same controller as the page you create the modal from. 每次创建新的模态时,即使您使用与创建模态页面相同的控制器,也将再次运行其背后的代码,有效擦除对其所做的任何更改。

To do what you want to do, you'll have to; 做你想做的事,你必须做;

var modal= $uibModal.open({
            templateUrl: ''
            }
        });
modal.result.then(function(array){
    $scope.rowArray = array
}

Your modal close function will then be; 然后,您的模式关闭函数将为:

$uibModalInstance.close($scope.rowArray);

This example will work if you're using the same controller for the modal and main HTML page, otherwise you'll need to have a resolve for your $uibModal.open to pass it through to the modal controller, but also add your rowArray to the dependencies of that controller. 如果为模态页面和主HTML页面使用相同的控制器,则此示例将起作用,否则,您需要对$ uibModal.open有一个解析,才能将其传递给模态控制器,还需要将rowArray添加到该控制器的依赖项。

Hope it helps! 希望能帮助到你!

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

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