How to pass form data from angular ui bootstrap modal to view

前端 未结 2 1631
无人共我
无人共我 2020-12-30 05:01

I\'m creating a webapp and I want to implement an option to add friends. I\'ve created the add friend page as a modal with a text input field. I want to test this by display

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 05:21

    I would suggest using the promise from the result to set the value to your controller's variables instead. The "resolve" from my understanding is for passing controller's variable to the dialog for using inside the dialog, not to be changed directly. In your code example, passing result you set in $modalInstance.close() to modalInstance.result.then() will do the trick. In other words, changing line #18 and #19 to the following,

    modalInstance.result.then(function (data) {
    $scope.user.name = data;
    

    To improve the code a bit, you can actually pass the entire user object to allow adding additional attributes such as email, address, etc. to your user object easily. I had create an example at http://plnkr.co/edit/oztYRNrCRlF1Pw289i1M?p=preview.

提交回复
热议问题