It is my first day and I'm trying to get a simple even workign but it isn't. Here's a fiddle: http://jsfiddle.net/LKktL/
<body ng-app>
<div ng-controller='EventAddCtrl'>
<p>Nothing here {{'yet' + '!'}}</p>
<div class='first-test' ng-click="say_hello()">angular test to say hello</div>
</div>
</body>
function EventAddCtrl($scope){
$scope.say_hello = function() {
alert('hello in there');
}
}
It's obviously not working and trying to figure out why. thx in advance
In your JSFiddle Angular is being executed during the onLoad
event. Open your browser console and you'll find the following error thrown by Angular
Error: Argument 'EventAddCtrl' is not a function, got undefined
Your App has failed to initialized.
The onLoad
event is fired at the end of the document loading process. Angular initializes your app during the DOMContentLoaded
event, which is fired after the DOM has been parsed but before the DOM is ready and before the document is fully loaded. In other words, make sure the library is parsed and executed before any of those events by either including it between <head>
or <body>
HTML tags. A good practice is to place it just before the closing <body>
tag.
As others have mentioned, when using JSFiddle, use either no wrap(head)
or no wrap(body)
.
There are two wrong usages in your fiddle.
<body>
tag in html panel which is already out there, and expand the info menu in the left panel, fill the Body Tag with <body ng-app>
. for more infomation, plz take a look at this page fiddle documentation.