Articles in this section
Category / Section

How to open dialog from another controller function using angular js

1 min read


When there is two different ng-controller one with a Dialog component and the other controller to open the dialog explicitly. To open the Dialog from other controller, we need to use ‘ng-include’ directive, ‘$includeContentLoaded’ event and ‘$broadcast’ service.


  1. Create a ng-controller for rendering ejDialog control with angular binding.
    <div class="control" ng-controller="Dialog_ctrl">
        <div id="basicDialog">
            <!--Angular is binded via model value ""-->
            <input id="name1" type="text" ng-model="" />
            <!--Angular is binded via model value ""-->
            <input id="address1" type="text" ng-model="" />
                    <td class="pad">
                        <!--On clicking the button updates the datasource-->
                        <input id="btn1" type="button" value="Submit" ej-button ng-click="press(user)" />
                    <td class="pad">
                        <!--On clicking the button close the dialog-->
                        <input id="btn2" type="button" value="Cancel" ej-button />


  1. Create another ng-controller with angular binding and using “ng-include” directive add the “basigDialog.html”(File name of the other controller). Please refer the following code snippet.
<html xmlns="" ng-app="DialogCtrl">
    <!--Required scripts here -->
    <div ng-controller="basic_controller">
        <input class="e-btn" type="button" style="display: block" ng-click="call_otherctrl()" id="btnOpen" value="Click to open dialog" ej-button e-click="dialogOpen" />
        <div ng-include="'basicDialog.html'"></div>
  1. Now to check whether any external resources added, bind $includeContentLoaded event that is emitted every time a component is included to the controller. Define script to initialize dialog control in it.
  2. Using $broadcast service bind the event for the child controllers. So that you can open the Dialog from this controller.
var obj;
// declaration
var myApp = angular.module('DialogCtrl', ['ejangular']);
myApp.controller('basic_controller', function ($rootScope) {            
    $rootScope.$on('$includeContentLoaded', function () {
            width: 550,
            height: 300,
            showOnInit: false,
            enableModal: true,
            title: "User Information"
        $rootScope.call_otherctrl = function () {
myApp.controller('Dialog_ctrl', ['$scope', function ($scope) {
    $scope.user = {};
    $ = "User";
    $ = "City";
    // angular binding for the other controller
    $scope.$on('Dialog_open', function (event) {
        obj = $(".e-dialog.e-js.e-widget-content").data("ejDialog");
        if (obj)
  ; // broadcast calls this event
    $ = function (user) {
        if (obj)



In the above sample, we have 2 controllers separately and initiated control from controller by referring the external resource. Find the sample from the below,


Sample link

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment