Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple AngularJS example with a module and controller in jsFiddle

This probably a combo jsFiddle/Angular question, but I'm trying to learn me some basic Angular and I'm not sure why it only works when I include the controller JS in the HTML pane. jsFiddle here

Basically the following works:

<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
 <h1>Welcome {{ name }}</h1>

<p>made by : {{userName}}</p>
<!-- Bind the input to the name -->
<input ng-model="name" name="name" placeholder="Enter your name" />
</div>
<script>
var myApp = angular.module('myAppModule', []);
myApp.controller('someController', function($scope) {
    // do some stuff here
    $scope.userName = "skube";
});
</script>

But if I try to move the JS within the script tag to the JavaScript pane, it fails.

like image 974
skube Avatar asked Jul 11 '26 12:07

skube


1 Answers

Take a look at this article for some info about jsFiddle with Angular

Also more examples on AngularJS Wiki that you could use: https://github.com/angular/angular.js/wiki/JsFiddle-Examples

like image 165
dimirc Avatar answered Jul 14 '26 04:07

dimirc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!