2

Just playing around with Angular and I can't get it to work. The binding works when I set my ng-app="" and nothing else. This is my html file:

<!DOCTYPE html>
<html>
    <head>
    <script  src="app/app.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    </head>
<body ng-app="myApp" ng-controller="myController">
<ul ng-repeat="x in names">
    <li >
        {{ x }}
    </li>
</ul>
</body>

And my app.js

var myApp = angular.module("myApp", []);

myApp.controller("myController", function($scope){
  $scope.names = ['a', 'b'];
});

Yes the js files are in the right place and refrenced properly. I'm using WebStorm. I keep seeing the {{x}} on my page. Instead of the names inside the scope.

2
  • works fine jsfiddle.net/Dipak1991/rxjzxaqo Commented Aug 21, 2015 at 5:27
  • 4
    You are loading angular.js later. Try to load first before app.js. Commented Aug 21, 2015 at 5:28

1 Answer 1

10

Your app.js should be linked after angular:

<!DOCTYPE html>
<html>

<head>
    <script src="bower_components/angular/angular.js"></script>
    <script src="app/app.js"></script>
</head>

<body ng-app="myApp" ng-controller="myController">
    <ul ng-repeat="x in names">
        <li>
            {{ x }}
        </li>
    </ul>
</body>

</html>
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.