0

I'm working through an angular tutorial and I have this output on the actual page: {{product.name}} ${{product.price}}

my html and js are below

<!DOCTYPE html>
<html ng-app="gemStore">
<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body class="container" ng-controller="StoreController as store">
<div class="product row" ng-repeat='product in store.products'>
    <h3>
        {{product.name}}
        <em class="pull-right">${{product.price}}</em>
    </h3>
</div>
</body>
</html>

and next the js

(function() {
  var app = angular.module('gemStore', ['bootstrap-tagsinput']);

  app.controller('StoreController', function(){
    this.products= gems;
  });

  var gems = [
    { name: 'Azurite', price: 2.95 },
    { name: 'Bloodstone', price: 5.95 },
    { name: 'Zircon', price: 3.95 },
  ];
})();

Any help on how to actually display the contents of product.name would be appreciated. Also why is the html not recognizing these braces {{}} and displaying java script for them?

5
  • those braces don't appear in your code anywhere? Commented Jan 26, 2015 at 14:29
  • 2
    var app = angular.module('gemStore', ['bootstrap-tagsinput']); Commented Jan 26, 2015 at 14:29
  • 2
    whenever angular is not parsing your markup and is outputting the raw expressions, it generally means that angular itself, your app, or one of your controllers failed to load correctly. What errors do you have in the console logs? Commented Jan 26, 2015 at 14:31
  • also, you defined your controller StoreController as store but then are referencing a product which isn't your controller, nor is it a property on your StoreController, so it's not clear where that is supposed to come from? I think you are missing an ng-repeat element here, something like ng-repeat = "product in store.gems" Commented Jan 26, 2015 at 14:38
  • Yeah I just fixed the part with the ng-repeat and products. Commented Jan 26, 2015 at 14:47

4 Answers 4

1

This line is wrong:

var app = angular.module('bootstrap-tagsinput', 'gemStore', []);

You can only have one main module, and your main app is gemStore so it should be something like this:

var app = angular.module('gemStore', ...
Sign up to request clarification or add additional context in comments.

Comments

0
<div ng-app='gemStore'>
<div class="container" ng-controller="StoreController as store">
<div class="product row">
    <h3 ng-repeat="product in products">
        {{product.name}}
        <em class="pull-right">${{product.price}}</em>
    </h3>
</div>
</div>
</div>

your angular controller file,

var app = angular.module('gemStore', []);

  app.controller('StoreController', function($scope){

     // var gems = [
    $scope.products=[  
    { name: 'Azurite', price: 2.95 },
    { name: 'Bloodstone', price: 5.95 },
    { name: 'Zircon', price: 3.95 },
  ];

  });

Want to test this code? please use this fiddle made for you, http://jsfiddle.net/xfeh06zg/

4 Comments

made few changes as required. if you any specification, let me know.
Thanks for the fiddle link but I think it might be an issue with the link and script tags in head
Your code will not work as you have made several mistakes ! Thats why, rather than suggesting you anything, I have come up with fiddle link.
Even your edited code will not work as still I can see the errors !
0

you have no scope called product. you have to define product scope in your controller see jsfiddle

View

<div ng-app="gemStore">
  <div class="container" ng-controller="StoreController as store">
    <div class="product row" ng-repeat="product in store.products">
      <h3>
        {{product.name}}
        <em class="pull-right">${{product.price}}</em>
      </h3>
 </div>

controller

(function() {
  var app = angular.module('gemStore', []);

  app.controller('StoreController', function(){
    this.products = gems;
  });

  var gems = [
    { name: 'Azurite', price: 110.50 },
    { name: 'Bloodstone', price: 22.90 },
    { name: 'Zircon', price: 1100 },
  ];
})();

Comments

0

I believe the issue is that I did not have the correct script src here is what the first link and script tags should have been:

`<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>`

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>

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.