加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何将结果从angular-ui-bootstrap的模态传递给父

发布时间:2020-12-17 17:34:57 所属栏目:安全 来源:网络整理
导读:根据 https://angular-ui.github.io/bootstrap/#/modal,我想将模态的结果传递给父级而不关闭,但在示例代码中,它们仅通过关闭向父级显示传递结果 $uibModalInstance.close($scope.selected.item); 我想在点击项目时将数据传递给父项,但我不知道这样做.我真的
根据 https://angular-ui.github.io/bootstrap/#/modal,我想将模态的结果传递给父级而不关闭,但在示例代码中,它们仅通过关闭向父级显示传递结果

$uibModalInstance.close($scope.selected.item);

我想在点击项目时将数据传递给父项,但我不知道这样做.我真的需要帮助.谢谢.

解决方法

这是关于控制器之间通信的一个相当普遍的问题,因为您不想关闭模型并希望将数据传递给不同的控制器.

问题的最快途径是使用$broadcast.在模态的控制器中,写如下:

// Make sure to use $rootScope
$rootScope.$broadcast("modalDataEventFoo",{selectedItem: $scope.selected.item});

现在,在您的父控制器中:

$scope.$on("modalDataEventFoo",function(event,data) {
     console.log("got the data from modal",data.selectedItem);
});

控制器之间通信的其他参考:

> What’s the correct way to communicate between controllers in AngularJS?
> https://egghead.io/lessons/angularjs-sharing-data-between-controllers
> http://www.angulartutorial.net/2014/03/communicate-with-controllers-in-angular.html
> Communication between controllers in Angular

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读