如何在 angularjs 模态窗口中运行 jquery

How to run jquery inside angularjs modal window?

本文关键字:运行 jquery 窗口 模态 angularjs      更新时间:2023-09-26

我在angularjs中使用ngDialod作为我的模态窗口。

我想在模态窗口中运行一些jQuery代码。

我创造了一个小提琴我的模态。如何在点击时定位id="target"

(为什么我需要这个,因为我正在计划在模态中一个简单的图像滑块)

请帮忙,

你的答案

http://jsfiddle.net/mb6o4yd1/6/

<div ng-controller="MyCtrl">
    <button ng-click="clickToOpen()">My Modal</button>
    <script type="text/ng-template" id="templateId">
        <div id="target" ng-click="test()" ng-controller="tt">
          Click here
        </div>
    </script>
</div>

var myApp = angular.module('myApp',['ngDialog']);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, ngDialog) {
    $scope.clickToOpen = function () {
        ngDialog.open({ template: 'templateId' });
    };
}
function tt($scope)
{
    $scope.test = function()
    {
        console.log("AaA");
    }
}

您可以将控制器传递给ngDialog并使用ng-click。

var myApp = angular.module('myApp',['ngDialog']);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, ngDialog) {
    $scope.clickToOpen = function () {
        ngDialog.open({ template: 'templateId',
                       controller : 'dialogCtr'});
    };

}
myApp.controller('dialogCtr', function($scope){
    $scope.clickTarget = function()
    {
        alert("hello");
    };
});
<div ng-controller="MyCtrl">
    <button ng-click="clickToOpen()">My Modal</button>
    <script type="text/ng-template" id="templateId">
        <div ng-click="clickTarget()" id="target">
          Click here
        </div>
    </script>
</div>