$ rootscope.$广播没有在“重新加载”页面上更新



第一个控制器:

$rootScope.$broadcast("CallParentMethod", {});

第二控制器:

$rootScope.$on("CallParentMethod", function() {
    $scope.getUserDetails();
})
$scope.getUserDetails = function() {
    HttpService.get("/customer/" + nationalId).then(function(resp) {
        if (resp.status == 'success') {
            console.log(resp.result)
            $rootScope.county_name = angular.copy(resp.result.county)
            $rootScope.campaign_name = angular.copy(resp.result.campaign)
            console.log($rootScope.campaign_name)
        }
    });
};

$scopes的混合物

有这个事件

$rootScope.$broadcast("CallParentMethod", {});

因此,您应该在儿童$范围中听这个事件,但是您正在 $rootScope

中听它
$rootScope.$on("CallParentMethod", function() {
    $scope.getUserDetails();
})

您可能想在定义getUserDetails()的相同范围内收听它

$scope.$on("CallParentMethod", function() {
    $scope.getUserDetails();
})

另一个提示:如果您不需要传递任何参数,则可以在$broadcasting

时忽略空对象{}
$rootScope.$broadcast("CallParentMethod")

最新更新