为什么NG-点击不行? [英] Why does ng-click not work?

查看:200
本文介绍了为什么NG-点击不行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动了这个问题,这个职位 - <一个href=\"http://stackoverflow.com/questions/35075313/angular-events-ng-click-do-not-work-with-other-libraries-dojo-knockout-kendo\">Angular事件,NG-点击,不与其他图书馆合作道场,淘汰赛,KendoUI,ESRI JSAPI

不管是什么我尝试,NG-点击不起作用。然而,作品的onclick。里面的范围,接线了一个上单击事件DOS无法正常工作。这是怎么回事?

编辑:我可以从命令行调用$ scope.myClick()。但它不会命中断点。它会显示一个警告窗口,但如果这就是所谓的从HTML指令中,功能是打不到。

编辑2:继承人plunker - https://plnkr.co/edit/ kK3NmWB9wfOopG7m5MYv?p = preVIEW

编辑3:好了,所以plunker工作,但可怕的应用程序,我需要添加一定角度必须与角的东西搞乱。任何想法可能在现有的应用程序被破坏角?这其他应用程序使用道场,道场装载机和require.js。一切正常,除了NG-click事件。

编辑4:我注释掉从这个应用程序,它加载道场,剑道UI,淘汰赛和ESRI JSAPI组件的初始化()调用,而这个角code。与NG-单击作品。我的直觉是淘汰赛与此捣乱。是否有可能完全隔离该应用程序的其余角?有什么建议?

下面是应用程序:

  VAR对myApp = angular.module('对myApp',[]);

指令:

  myApp.directive('rapidReport',
功能(){
    返回{
        限制:'E'
    }
});  &LT; D​​IV CLASS =LS-rapidReports&GT;
        &LT; D​​IV NG-应用=对myApp&GT;
            &LT; D​​IV ID =rapidreportCtrlNG控制器=rrController&GT;
                &LT;按钮式=按钮NG点击=MyClick认证()&GT;&赫赫LT; /按钮&GT;
            &LT; / DIV&GT;        &LT; / DIV&GT;
    &LT; / DIV&GT;

控制器:

  myApp.controller('rrController',
功能rrController($范围){    $ scope.myClick =功能(){
        调试器;
    };
});


解决方案

下面的问题是:

  VAR对myApp = angular.module('对myApp',[]);

应该是:

  VAR对myApp = angular.module('对myApp',[]); //对myApp没有空间之前

-

修改:现在我把它固定在plnkr。如果您INFACT尝试在对myApp声明中再次添加空间,你会在控制台看到以下错误消息。

 未捕获的错误:[$喷油器:modulerr]未能实例由于模块对myApp:
错误:[$喷油器:NOMOD]模块'对myApp'不可!你要么拼写错误的模块名称,或忘了加载它。如果注册一个模块,确保指定的依赖关系作为第二个参数。

你可以从错误日志中扣除,在的script.js 未与一个在NG-程序指令相匹配的应用程序声明 index.html的,所以应用程序不能正常工作。

Moved this question to this post - Angular events, ng-click, do not work with other libraries Dojo, Knockout, KendoUI, ESRI JSAPI

No matter what I try, ng-click does not work. However, onclick works. Inside the scope, wiring up an on click event dos not work. What is going on?

EDIT: I can call the $scope.myClick() from the command line. But it will not hit the breakpoint. It will show an alert window, but if this is called from within HTML directive, the function is not hit.

EDIT 2: heres a plunker - https://plnkr.co/edit/kK3NmWB9wfOopG7m5MYv?p=preview

EDIT 3: Ok, so the plunker works, but the horrible application I need to add angular to must messing with something in angular. Any ideas what could be breaking Angular in an existing app? This other app uses dojo, dojo loaders, and require.js. Everything works, except for the ng-click event.

EDIT 4: I commented out an Init() call from this application which loads Dojo, Kendo UI, Knockout, and ESRI JSAPI components, and this Angular code with ng-click works. My gut feeling is knockout is messing with this. Is it possible to completely isolate Angular from the rest of this application? Any suggestions?

here is the app:

var myApp = angular.module('myApp ', []);

directive:

myApp.directive('rapidReport',
function () {
    return {
        restrict: 'E'
    }
});

  <div class="ls-rapidReports">
        <div ng-app="myApp">
            <div id="rapidreportCtrl" ng-controller="rrController">
                <button type="button" ng-click="myClick()">hehe</button>
            </div>

        </div>
    </div>

controller:

myApp.controller('rrController',
function rrController($scope) {

    $scope.myClick = function () {
        debugger;
    };


});

解决方案

Here is the problem:

var myApp = angular.module('myApp ', []);

which should be:

var myApp = angular.module('myApp', []); //myApp without space before '

-

EDIT: Now I see it fixed in the plnkr. If you infact try to add the space again in myApp declaration you will see the following error message in the console.

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

As you can deduct from the error log, the app declaration in the script.js wasn't matching with the one in the ng-app directive in index.html, so the app wasn't working.

这篇关于为什么NG-点击不行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆