javascript - ng-repeat not outputting results -
i'm still new @ learning , though had right, i'm unable output fruits in first app. i'm using ng-repeat= "foods in body.fruits" output, nothing showing. ideas?
<!doctype html> <html ng-app="app"> <head> <title>bootstrap 3</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="app.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mtjoasx8j1au+a5wdvnpi2lkffwweaa8hdddjzlplegxhjvme1fgjwpgmkzs7" crossorigin="anonymous"> <link href="index.css" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="css/reset.css"> </head> <body ng-controller="bodycontroller body"> <div class="navbar navbar-inverse navbar-static-top"> <div class="container"> <div class="navbar-header"> <button class="navbar-toggle" data-toggle="collapse" data-target=".navheadercollapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a href="#" class="navbar-brand">tech site</a> </div> <div class="collapse navbar-collapse navheadercollapse"> <ul class="nav navbar-nav"> <li><a href="#">specs , features</a></li> <li><a href="#">how videos</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">social media <b class = "caret"></b></a> <ul class="dropdown-menu "> <li><a href="#">twitter</a></li> <li><a href="#">facebook</a></li> <li><a href="#">google+</a></li> <li><a href="#">instagram</a></li> </ul> </li> <li></li> </ul> </div> </div> </div> <div class="container"> <div class="row"> <div class="col-md-2 " ></div> <div class="col-md-8 " > <div id="applefacts" ng-repeat= "foods in body.fruits"></div> </div> <div class="col-md-2 " ></div> </div> </div> <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0msbjdehialfmubbqp6a4qrprq5ovfw37prr3j5elqxss1yvqotnepnhvp9aj7xs" crossorigin="anonymous"></script> </body> </html>
app.js
(function() { var app = angular.module('app', []); app.controller("bodycontroller", function(){ this.foods = fruits; }); var fruits = [ { name: 'apples', calories: 65, totalfat: '0g', saturated_fat: '0g', cholestrol: '0mg', sodium: '1mg', totalcarbs: '17g', dietaryfiber: '3g', sugar: '13g', protein: '0g', vitamina: '1%', vitaminc: '10%', calcium: '1%', iron: '1%' }, { name: 'oranges', price: 5.95 }, { name: 'pineapple', price: 3.95 } ]; })();
in app.js file, need utilize $scope module. how access properties js file in html file. like:
app.controller("bodycontroller", function($scope){ $scope.foods = fruits;
and in html:
<div id="applefacts" ng-repeat= "food in foods"> {{food.name}} </div>
and access other properties objects syntax above: {{food.calories}} or {{food.price}} etc.
Comments
Post a Comment