第一个控制器:
$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")