小编Gil*_*Moa的帖子

使用$ emit和$ on从子模态到父angularjs

我有这种情况

两个文件,都在同一个应用程序中

var app = angular.module('myapp');
Run Code Online (Sandbox Code Playgroud)

文件一是父母,我有:

app.controller("ControllerOne", ['$scope', '$http', '$modal', 
function ($scope, $http, $modal) {


$scope.$on('refreshList', function (event, data) {
    console.log(data);
});

$scope.openModal = function () {

    var modalInstance = $modal.open({
        templateUrl: '/SomeFolder/FileWithControllerTwo',
        controller: 'ControllerTwo',
        size: 'lg',
        resolve: {
            someParam: function () {
                return "param"
            }
        }
    });
}

}]);
Run Code Online (Sandbox Code Playgroud)

文件二是孩子,我有:

app.controller("ControllerTwo", ['$scope', '$http', 'someParam',
    function ($scope, $http, someParam) {


        $scope.SaveSomething = function () {

            $http.post(url, obj)
                .success(function (data) {

                        $scope.$emit('refreshList', [1,2,3]);

                }).error(function () {

                });

        };

    }]);
Run Code Online (Sandbox Code Playgroud)

假设我可以打开模态,我可以"SaveSomething". …

angularjs

3
推荐指数
1
解决办法
3323
查看次数

标签 统计

angularjs ×1