2

I'm attempting to learn Angular JS. I have written this small piece of code, but for some reason I cannot get the HTML to recognize the Angular.JS.

My index.html file:

<!DOCTYPE HTML>
<html ng-app="store">
   <head>
     <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css"/>
   </head>
   <body>
       <div ng-controller = "storeController as store">
           <h1>{{store.product.name}}</h1>
       </div>
       <script type = "text/javascript" src = "angular-1.2.29/angular.min.js"></script>
       <script type = "text/javascript" src= "app.js"></script>
  </body>
</html>

My app.JS file:

(function () {
var app = angular.module('store', [ ]); 
app.controller('StoreController', function() {
    this.product = item;
});
var item = {
    name: 'stuff',
    price: 2.44,
    description: 'lame',
}
})();

My output is {{store.product.name}}, instead of the 'stuff' that i'm expecting.

2 Answers 2

3

I would advise to try and match the case:

<div ng-controller = "StoreController as store">

Capital S.

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

2 Comments

That did it!, thanks. I've checked this thing 100 times, I can't believe I missed that.
Haha this happens to me all the time ;)
1

Fix that line

 <div ng-controller = "storeController as store">

to

 <div ng-controller="StoreController">

'Controller as syntax' is a good thing, but in your case you named app with the same name.

And made a typo in 's' instead 'S' as @Idos noticed

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.