Why does ng-click not work in case-1, but does in case-3?

angularjs

Solution

`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).

Problem

There is clearly something fundamental im not yet understanding. 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/

Original source

Related problems