JSFiddle - React, Tailwind, and code Playground

by James Allardice

HTML

<div ng-app="EventDemo" ng-controller="EventCtrl">
    <button ng-click="$broadcast('event')">Broadcast</button> <!-- Broadcast event from parent scope -->
    <button ng-click="$emit('event')">Emit</button>
    Parent scope: {{ count }}
    <div ng-controller="EventCtrl">
         Child scope: {{ count }}
    </div>
</div>

JavaScript

angular
    .module("EventDemo", [])
    .controller("EventCtrl", [
        "$scope",
        function ($scope) {
            $scope.count = 0;    // Initial model value
            $scope.$on("event", function () {    // Listen for "event" events
                $scope.count++;    // Update the model
            });
        }
    ])
;