angularjs – 如何将结果从angular-ui-bootstrap的模态传递给父而不关闭?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何将结果从angular-ui-bootstrap的模态传递给父而不关闭?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据 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

猜你在找的Angularjs相关文章