For a mockup I need a simple mechanism like
ng-click="alert('Clicked')"
but the code above is not working, can someone help me? I don't want to touch the Controller..
For a mockup I need a simple mechanism like
ng-click="alert('Clicked')"
but the code above is not working, can someone help me? I don't want to touch the Controller..
As Neeraj mentioned, the accepted answer does not work. Add something like this to your controller to avoid an
Illegal Invocation
error:Refer to previous answer, ng-click = "alert('Hello World!')" will work only if $scope points to window.alert i.e
But even it creates eval problem so correct syntax must be:
HTML
Controller
As far as I know,
ng-click
works only within your$scope
. So you would only be able to call functions, defined in your$scope
itself. To use alert, you may try accessing thewindow
element, just by usingwindow.alert('Clicked')
.EIDT: Thanks to Ibrahim. I forgot. You shouldn't be able to use
window.alert
, as far as you won't define:In this case, using
alert('Clicked')
in yourng-clicked
directive should work. But at the end, this method would not solve your problem of not touching your controller.