Haris Z
Haris Z

Reputation: 119

getting started angularjs failed

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!";
});

Upvotes: 2

Views: 47

Answers (2)

Subash
Subash

Reputation: 230

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

Upvotes: 1

Pirate X
Pirate X

Reputation: 3095

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

Upvotes: 1

Related Questions