0

I am trying to initiate the opening of a modal window and instead of triggering it with "ng-click", I would like to call an angular expression from another JS function. How can I do that?

Current implementation:

index.html

<div ng-controller="modalWindow" class="text-letf">
  <a class="button button-default" ng-click="openModal()">Open Modal</a>
</div>

modal.js

   var app = angular.module('app', ['ui.bootstrap']);
    app.controller('modalWindow', function ($scope, $uibModal) {
    $scope.openModal = function () {
        $uibModal.open({
            template: ['<div class="modal-header">',
                '<a class="close" ng-click="$dismiss()"><span class="icon-close"></span></a>',
                '<h1 class="modal-title">Example Modal</h1>',
            '</div>',
            '<div class="modal-body">',
                '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing</p>
            '</div>',
            '<div class="modal-footer">',
                '<a class="button button--fixed" ng-click="$dismiss()">Cancel</a>',
                '<a class="button button--fixed button--cta" ng-click="$close()">OK</a>',
            '</div>'].join(' ')
        });
    }
});

My task is to call openModal expression from another function:

// Form a modal window
marker[element.dev_addr].on('click',function() {

  // Was trying to trigger opening by addressing to the controller
  // but with no luck so far.
  angular.element(document.getElementById('modalWindow'))
         .triggerHandler('click');
});
Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46
A.R.
  • 1
  • The answer is here http://stackoverflow.com/questions/13743058/how-to-access-the-scope-variable-in-browsers-console-using-angularjs – TMG Apr 09 '16 at 15:31
  • Why dont you just do: marker[element.dev_addr].on('click',function() { $scope.openModal() }); If they are not in the same scope you could use rootscope emit and broadcast to trigger it. – user3791775 Apr 09 '16 at 16:49

0 Answers0