In angularJs, the $broadcast (), parent transmits data to the son, why can't he receive the duck?

< body ng-app= "app" >

<div ng-controller="parentContrl">
    <h1>{{name}}</h1>
    <div ng-controller="childContrl">
        <h1>{{message}} </h1>
    </div>
</div>

< / body >

< / html >
< script >

var app = angular.module("app", []);

app.controller("parentContrl", ["$scope", function ($scope) {
    $scope.name = "hello"
    $scope.$broadcast("call", $scope.name)
}]);

app.controller("childContrl", ["$scope", function ($scope) {
    $scope.$on("call", function (e, data) {
        $scope.message = data;
    })
}])

< / script >

Feb.23,2022

< H2 > reason: < / H2 >

Controller instantiation sequence causes.

< H2 > add: < / H2 > The instantiation of the

Controller is instantiated according to the location order of the html, so the parent class Controller is instantiated first, and the broadcast is sent, while the subclass does not complete the registration of the broadcast monitoring registration. Lose this broadcast.

you can delay the parent broadcast, or change it to broadcast after clicking, and the subclass can receive it normally
.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e493c1-432cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e493c1-432cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?