NG-点击不火的javascript全局函数 [英] ng-click does not fire javascript global function

查看:106
本文介绍了NG-点击不火的javascript全局函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来AngularJS,我已经把一个NG点击
NG-重复,并且click事件拒绝开火。如果我用一个简单的onclick,
,它虽然工作。

I'm new to AngularJS, and I've put an ng-click on a radio button generated by ng-repeat, and the click event refuses to fire. If I use a simple onclick, that does work though.

这工作,我看到了警告:

This works, and I see the alert:

<div class="span2 left-justify"
        ng-repeat="choice in physicalmode_choices">
    <input type="radio"
            name="physical_layer"
            value="{{ choice.private }}"
            onclick="alert('foo')"
            required
            ng-model="$parent.networkoptions.physicalmode" />
            &nbsp;<span ng-bind="choice.public"></span>
</div>

但是,这并不:

<div class="span2 left-justify"
        ng-repeat="choice in physicalmode_choices">
    <input type="radio"
            name="physical_layer"
            value="{{ choice.private }}"
            ng-click="alert('foo')"
            required
            ng-model="$parent.networkoptions.physicalmode" />
            &nbsp;<span ng-bind="choice.public"></span>
</div>

我可以不与NG单击做到这一点?还是我误解的EX pression是什么?

Can I not do this with an ng-click? Or am I misunderstanding what an "expression" is?

谢谢,
迈克

推荐答案

要澄清DerekR的答案。

To clarify DerekR's answer.

在角看到

ng-click='alert("test")'

它看起来

$scope.alert

这很可能是不确定的。

which is likely to be undefined.

您需要提供范围的代理方法,或者甚至可能rootscope。

You need to provide a proxy method on the scope, or possibly even rootscope.

例如:

$rootScope.log = function(variable) {
    console.log(variable);
};
$rootScope.alert = function(text) {
    alert(text);
};

请参阅:<一href=\"http://deansofer.com/posts/view/14/AngularJs-Tips-and-Tricks-UPDATED#scopemethods\">http://deansofer.com/posts/view/14/AngularJs-Tips-and-Tricks-UPDATED#scopemethods

这篇关于NG-点击不火的javascript全局函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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