【问题标题】:angular Controller event is not firing on custom alert角度控制器事件未在自定义警报上触发
【发布时间】:2014-12-27 11:51:37
【问题描述】:

我的问题是 Click 事件没有从 alert.html 触发。

在 index.html 中,我包含了分配给 outputController 的 output.html,在 output.html 中,我包含了 alert.html,默认情况下,alert.html 将被隐藏。

当我单击 output.html 中的按钮时,它会触发 openWindow() 方法,在其中会调用 javascript alert 方法。 (因为我们已经覆盖了 window.alert 方法来更改普通基本警报的视图。)我可以在警报对话框中获取视图,甚至可以访问 alert.html 中的 $scope 成员变量,但我的问题是我不能触发点击事件。有人建议我的代码可能有什么问题。

OutputController.js

  App.controller('OutputController',[ '$scope',function($scope){
    $scope.testVal = "Ajith";
        $scope.checkClick = function () {
            console.log("Clicked");
        };
 $scope.openWindow = function (title) {
        alert(angular.element(document.querySelector("#HtmlA"))).html(), title);
       };
}]);


index.html

 <div class="tabpage" id="tabpage_4"  ng-controller="OutputController">
            <div class="outputTab" ng-include src="'views/output.html'"></div>
        </div>

output.html

 <input type="button"  ng-click="openWindow('A')" value="OenAlert"/>
        <div id="HtmlA" ng-controller="OutputController" ng-init="Type = 'A'"
             ng-include="'views/alert.html'" ng-hide="true"></div>

alert.html

    {{testVal}}
<input type="button" ng-click="checkClick()" value="Click Here"/>

【问题讨论】:

  • 您是否提醒 html 代码位于具有 ng-controller 的 div 下?
  • 我没有在 alert.html 代码中单独提到控制器,但我认为当你包含在控制器中时,所有包含的 html 文件都可以访问控制器范围。
  • 关于 ng-include 和 ng-controller 的组合存在 Angular 问题。此处已解决:github.com/angular/angular.js/issues/4431 因此,在修复之前,您应该避免将它们一起使用。
  • 不确定,看起来可以plnkr.co/edit/ERGYkRZd06R9LhgYOVYp?p=preview ?
  • @dfsq 我可以从 output.html 中获取事件,但我无法从我的自定义警报视图中触发事件。我用自定义 html 弹出警报对话框。

标签: angularjs modal-dialog angularjs-scope angularjs-ng-include


【解决方案1】:

根据上述建议,我删除了我的custom alert,我使用了angular-ui modal popup。它工作正常。

http://plnkr.co/edit/FEtJo3?p=preview

【讨论】:

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