Tuesday, 29 August 2017

$on $emit and $broadcast in Angularjs







<html>
<head>
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/AngularT2.js"></script>
    <script src="~/Scripts/AreaService.js"></script>
</head>
<body ng-app="myapp">
  

    <div ng-controller="TopLevel" style="border:solid;">
        <b> Top Level</b> <button ng-click="SendDownword()">SendDown</button>

        <div ng-controller="MiddleLevel" style="border: solid; ">
            <b> Middle Level</b>
            <div ng-controller="LowerLevel" style="border: solid; ">
                <b> Lower Level</b>
                <button ng-click="SendUpword()">SendUp</button>
            </div>
        </div>

    </div>


</body>
</html>


/// <reference path="angular.min.js" />
var app2 = angular.module("myapp", []);

app2.controller("TopLevel", function ($scope) {
    $scope.$on("myevent", function (event, args) {
        alert("This is parent ="+args);
    });

    $scope.SendDownword = function () {
        $scope.$broadcast("myevent", "sent down");
    }
   
});

app2.controller("MiddleLevel", function ($scope) {
    $scope.$on("myevent", function (event,data) {
        alert("this is middle=" + data);
    });

});

app2.controller("LowerLevel", function ($scope) {
    $scope.$on("myevent", function (event, data) {
        alert("this is lower level=" + data);
    });

    $scope.SendUpword = function () {
        $scope.$emit("myevent", "sent up");
    }
});



});

20 comments:

  1. I really appreciate the information shared above. It’s of great help. MaxMunus provides Remote Support For Corporate and for Individuals. If anyone is facing any issue in his project of #Angular JS, we can support them remotely , kindly Contact MaxMunus
    MaxMunus Offer World Class Industry best Consultant on #Angular JS. We provide end to end Remote Support on Projects. MaxMunus is successfully doing remote support for countries like India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: avishek@maxmunus.com
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    www.MaxMunus.com

    ReplyDelete
  2. Hi Buddy,

    What a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this.

    I have started using ag-grid in my the Angular 4 project and was unable to find any API's for performing in-line cell validations i.e. whenever the user edits a particular cell, the requirement is to perform a required field and pattern validation. In case of any validation errors, the corresponding editable field should get highlighted and an error message needs to be displayed.
    I have used the following cell events to fulfill the above purpose, but none of them provided me the desired result.
    • cellEditingStarted
    • cellEditingStopped

    I look forward to see your next updates.

    MuchasGracias,

    ReplyDelete
    Replies
    1. Thanks MuchasGracias for liking my post . In Next few days i will try post about your query with example and project code.......

      Delete
  3. Hiiii....Thanks for sharing Great information....Nice post....Keep move on...
    Angular JS Training in Hyderabad

    ReplyDelete
  4. Thanks for sharing the source code. Great information. Keep blogging. Are you looking for an best Angular training in kochi just visit https://www.xploreitcorp.com.

    ReplyDelete
  5. Great site and a great topic as well I really get amazed to read this.Thanks for sharing this wonderful content.its very useful to us.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    Full Stack Training in Chennai | Certification | Online Training Course
    Full Stack Training in Bangalore | Certification | Online Training Course

    Full Stack Training in Hyderabad | Certification | Online Training Course
    Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai
    Full Stack Training

    Full Stack Online Training


    ReplyDelete
  6. This is a terrific article,above concept was very clear to angular and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
    =DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete
  7. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? keep up!!

    Java training in Chennai

    Java Online training in Chennai

    Java Course in Chennai

    Best JAVA Training Institutes in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Training

    Java Online Training

    ReplyDelete
  8. Great site and a great topic as well I really get amazed to read this.Thanks for sharing this wonderful content.its very useful to us.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.


    AWS Course in Chennai

    AWS Course in Bangalore

    AWS Course in Hyderabad

    AWS Course in Coimbatore

    AWS Course

    AWS Certification Course

    AWS Certification Training

    AWS Online Training

    AWS Training

    ReplyDelete
  9. According to many websites, Scala is faster than Java. Some programmers even claim that Scala is 20% faster than Java. Both these programming languages run on JVM. ... Also, the Scala developers have option to use several Java development libraries and frameworks as it is also a JVM language..keep it up!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training


    ReplyDelete
  10. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. 스포츠티비

    ReplyDelete