【问题标题】:How to run jquery inside angularjs modal window?如何在 angularjs 模态窗口中运行 jquery?
【发布时间】:2015-03-08 18:02:00
【问题描述】:

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

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

我创建了一个小提琴My Modal。如何在点击时定位id="target"

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

请帮忙,

【问题讨论】:

  • 如果您在这里发布您的代码,而不仅仅是在 JSfiddle 上,我们将不胜感激。
  • 对不起,我还没有任何代码。

标签: javascript jquery angularjs angular-ui


【解决方案1】:

你的答案

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");
    }
}

【讨论】:

    【解决方案2】:

    您可以将控制器传递给 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多