简体   繁体   English

在angularjs中,我的点击功能不起作用有人可以帮我吗

[英]In angularjs my click function is not working can anybody help me

alert in click event is not working. 单击事件中的警报不起作用。 if i use alert outside of the function it will work.but i need this alert on button click. 如果我在功能之外使用警报,它将正常工作。但是我需要在按钮单击时发出此警报。 how to do it.? 怎么做。?

My coding is here 我的编码在这里

<div ng-app="indexapp" class="main">
    <div ng-controller="timectrl" class="timediv">
        <li><a ng-click='go()'>Like</a></li>    
    </div>
</div>

my script 我的剧本

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

app.controller('timectrl', function($scope) {
    $scope.go = function() {
        alert('hi');
    }
});

Try: href="" 试试:href =“”

See: 看到:

https://docs.angularjs.org/api/ng/directive/a https://docs.angularjs.org/api/ng/directive/a

Havent tested yet. Havent尚未测试。

I am guessing that ng-click should work here IF you click on the text 'Like' (because you applied ng-click to <a> rather than <li> ). 我猜测如果单击文本“赞”,则ng-click应该可以在这里工作(因为您将ng-click应用于<a>而不是<li> )。

If thats the case, move ng-click to the <li> item: 如果是这样,请将ng-click移至<li>项:

<li ng-click='go()'><a>Like</a></li>
<div ng-app="indexapp" class="main">
    <div ng-controller="timectrl" class="timediv">
        <li><a ng-click='events.go()'>Like</a></li>    
    </div>
</div>

And your controller, 还有你的控制器

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

app.controller('timectrl', function($scope) {
    $scope.events = {};
    $scope.events.go = function() {
        alert('hi');
    }
});

Try this one. 试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM