AngularJS从模态中传回数据 [英] AngularJS passing data back from modal

查看:83
本文介绍了AngularJS从模态中传回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在这里有所帮助...我正在考虑将AngularJS用于一些我想到的项目.当前正在尝试使用Bootstrap UI指令.请在这里查看我的代码: http://pastebin.com/zJGpNLep

I'd appreciate some help here... I am looking at making use of AngularJS for a few projects I have in mind. Currently experimenting with the Bootstrap UI directive. Please take a look at my code here: http://pastebin.com/zJGpNLep

有没有一种方法可以用模态生成的$ scope.formData中的数据更新$ scope.groups?我尝试了$ scope.groups.push($ scope.formData),但事实证明该方法不成功,并且只有通过刷新页面才能看到新数据.

Is there a way I can update $scope.groups with the data from $scope.formData which is generated from a modal? I have tried $scope.groups.push($scope.formData) which has proved unsuccessful and only way I can see the new data is by refreshing the page.

任何想法?

谢谢

推荐答案

您在正确的轨道上,只是省略了以下几行:

You're on the right track, you just left out these lines:

modalInstance.result.then(function (formData) {
  //use formData
});

这应该在$ scope.showAddGroupModal函数的末尾,如此处的bootstrap-ui示例所示:

This should go at the end of your $scope.showAddGroupModal function as shown in the bootstrap-ui example here:

$scope.open = function () {

  var modalInstance = $modal.open({
    templateUrl: 'myModalContent.html',
    controller: ModalInstanceCtrl,
    resolve: {
      items: function () {
        return $scope.items;
      }
    }
  });

  modalInstance.result.then(function (selectedItem) {
    $scope.selected = selectedItem;
  }, function () {
    $log.info('Modal dismissed at: ' + new Date());
  });
};

这篇关于AngularJS从模态中传回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆