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');
}
});
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>
).
If thats the case, move ng-click
to the <li>
item:
<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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.