为什么NG-单击不可的情况下,-1工作,但确实的情况下,3? [英] Why does ng-click not work in case-1, but does in case-3?

查看:101
本文介绍了为什么NG-单击不可的情况下,-1工作,但确实的情况下,3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很明显的东西根本IM尚未理解。

There is clearly something fundamental im not yet understanding.

我试着让模态模块的用户角Ui.Bootstrap但即时发现点击次数没有激活的open()功能 - 因此沸腾下来一个非常简单的测试用例,如下,即时通讯没有看到任何电话时NG-单击指向一个函数(警报或执行console.log),但不工作的时候NG-点击点东西只是一个前pression

Im trying to make user of the Modal module in Angular Ui.Bootstrap but im finding that my clicks are not activating the open() function -- So boiling it down to a very simple testcase, as below, im not seeing any calls when the ng-click points to a function (alert or console.log), but does work when the ng-click points to something which is just an expression

为什么警报在第一个例子不叫?

Why is the alert not called in the first example?

<div data-ng-app>
    <button data-ng-click="alert('Message 1');">
        ngClick -- not working, why not?
    </button>
    <button onclick="alert('Message 2');">
        Plain onclick
    </button>
    <button data-ng-click="count = (count + 1)">
          But this works, why ???
    </button>
    count: {{count}}
</div>

http://jsfiddle.net/H2wft/1/

推荐答案

NG-点击是为与无论是在当前范围内(函数使用,因此例如 $ scope.alert = window.alert 将解决不能够提醒有问题)或前角pression。它看起来像角不允许你在那里使用全球范围内的方法(它可能了寻找他们在目前的 $范围,从他们缺少)。

ng-click is meant for use with either a function in the current scope (so for example $scope.alert = window.alert would solve the problem of not being able to alert there) or an angular expression. it looks like angular does not allow you to use global scope methods in there (it might be looking them up in the current $scope, from which they are missing).

这篇关于为什么NG-单击不可的情况下,-1工作,但确实的情况下,3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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