从javascript函数

时间:2016-04-09 15:28:20

标签: javascript jquery angularjs

我试图启动模态窗口的打开,而不是用“ng-click”触发它,我想从另一个JS函数调用一个角度表达式。我怎么能这样做?

目前的实施:

的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(' ')
        });
    }
});

我的任务是从另一个函数调用openModal表达式:

// 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');
});

0 个答案:

没有答案