2

Not sure why is this not working

https://jsfiddle.net/0616b9ks

<body ng-app="main" id="homepage">
  <h1 ng-controller="homepageCtrl">hello {{test}}</h1>
</body>

JS

var app = angular.module("main", [])

.controller("homepageCtrl", function($scope) {
  $scope.test = "World!";
});
8
  • You should start by including angular.js Commented Jun 13, 2016 at 8:33
  • include angular in you fiddle :) Commented Jun 13, 2016 at 8:34
  • I alrdy did, look at this fiddle jsfiddle.net/Lt7aP/4, does it use the script tag? no right? Commented Jun 13, 2016 at 8:34
  • @HarisZ It does use Angular 1.2.1 with LoadType as onLoad Commented Jun 13, 2016 at 8:38
  • @PirateX and mine too jsfiddle.net/0616b9ks Commented Jun 13, 2016 at 8:42

2 Answers 2

1

Your code is fine. It's the jsfiddle which was creating the trouble.

Switch the load type from onLoad to No Wrap - in <head> Just tested it on your fiddle. Works like a charm.

Why it works?
JsFiddle wraps the code in a ready or load event by default & Angular may not get what it needs in the global scope when compiling your code. No wrap in <head> just loads the script in the head, without a wrap.

Give this a read if you use jsfiddle a lot for Angular, it'll save you a lot time- Using jsFiddle with Angular

enter image description here

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

Comments

1

In Js Fidle Switch the load type from onLoad to No Wrap - in

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.