3

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.

3
  • 3
    No wrap - in <head> jsfiddle.net/E9bU5/3 Commented Jan 28, 2014 at 21:58
  • I swear I tried that, but you're correct. What does "No wrap - in <head>" mean? It doesn't make sense to me Commented Jan 28, 2014 at 22:00
  • 2
    jsFiddle wraps your code in a ready or load event by default, and Angular might not find what it needs in the global scope when compiling your template at the time is needed. No wrap in <head> just loads the script in the head, without a wrap. Commented Jan 28, 2014 at 22:04

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.