Angularjs Code not showing anything -
i new angularjs, have designed code show food items, dont know problem is...it gives nothing output. have tried everything, cant seem find problem.
<!doctype html> <html lang="en" ng-app="confusionapp"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- above 3 meta tags *must* come first in head; other head content must come *after* these tags --> <title>ristorante con fusion: menu</title> <!-- bootstrap --> <link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="../bower_components/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet"> <link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet"> <link href="styles/bootstrap-social.css" rel="stylesheet"> <link href="styles/mystyles.css" rel="stylesheet"> <!-- html5 shim , respond.js ie8 support of html5 elements , media queries --> <!-- warning: respond.js doesn't work if view page via file:// --> <!--[if lt ie 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <div class="container"> <div class="row row-content" ng-controller="dishdetailcontroller"> <div class="col-xs-12"> <div class="media-left media-middle"> <a href=""> <img ng-src={{dish_cmnt.image}} alt="uthapizza"> </a> <div class="media-body"> <h2 class="media-heading">{{dish_cmnt.name}} <span class="label label-danger">{{dish_cmnt.label}}</span> <span class="badge">{{dish_cmnt.price | currency}}</span></h2> <p>{{dish_cmnt.description}}</p> </div> </div> </div> <div class="col-xs-9 col-xs-offset-1"> </div> </div> </div> <script src="../bower_components/angular/angular.min.js"></script> <script> var app = angular.module('confusionapp',[]); app.controller('dishdetailcontroller', function() { var dish_cmnt={ name:'uthapizza', image: 'images/uthapizza.png', category: 'mains', label:'hot', price:'4.99', description:'a unique combination of indian uthappam (pancake) , italian pizza, topped cerignola olives, ripe vine cherry tomatoes, vidalia onion, guntur chillies , buffalo paneer.', comments: [ { rating:5, comment:"imagine eatables, living in confusion!", author:"john lemon", date:"2012-10-16t17:57:28.556094z" }, { rating:4, comment:"sends heaven, wish mother-in-law eat it!", author:"paul mcvites", date:"2014-09-05t17:57:28.556094z" }, { rating:3, comment:"eat it, eat it!", author:"michael jaikishan", date:"2015-02-13t17:57:28.556094z" }, { rating:4, comment:"ultimate, reaching stars!", author:"ringo starry", date:"2013-12-02t17:57:28.556094z" }, { rating:2, comment:"it's birthday, we're gonna party!", author:"25 cent", date:"2011-12-02t17:57:28.556094z" } ] }; this.dish = dish; }); </script> </body> </html>
firstly, missing ng-app="confusionapp" added that.
next, template didn't have reference dishdetailcontroller did using ng-controller="dishdetailcontroller ctrl" , using ctrl.dish_cmnt instead of direct dish_cmnt.
next, this.dish = dish throwing error since dish undefined. changed this.dish_cmnt = dish_cmnt since needed reference dish_cmnt anyway.
that fixed it.
here's working code snippet.
var app = angular.module('confusionapp', []); app.controller('dishdetailcontroller', function() { var dish_cmnt = { name: 'uthapizza', image: 'images/uthapizza.png', category: 'mains', label: 'hot', price: '4.99', description: 'a unique combination of indian uthappam (pancake) , italian pizza, topped cerignola olives, ripe vine cherry tomatoes, vidalia onion, guntur chillies , buffalo paneer.', comments: [{ rating: 5, comment: "imagine eatables, living in confusion!", author: "john lemon", date: "2012-10-16t17:57:28.556094z" }, { rating: 4, comment: "sends heaven, wish mother-in-law eat it!", author: "paul mcvites", date: "2014-09-05t17:57:28.556094z" }, { rating: 3, comment: "eat it, eat it!", author: "michael jaikishan", date: "2015-02-13t17:57:28.556094z" }, { rating: 4, comment: "ultimate, reaching stars!", author: "ringo starry", date: "2013-12-02t17:57:28.556094z" }, { rating: 2, comment: "it's birthday, we're gonna party!", author: "25 cent", date: "2011-12-02t17:57:28.556094z" } ] }; this.dish_cmnt = dish_cmnt; }); <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- above 3 meta tags *must* come first in head; other head content must come *after* these tags --> <title>ristorante con fusion: menu</title> <!-- bootstrap --> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> </head> <body ng-app="confusionapp"> <div class="container"> <div class="row row-content" ng-controller="dishdetailcontroller ctrl"> <div class="col-xs-12"> <div class="media-left media-middle"> <a href=""> <img ng-src={{ctrl.dish_cmnt.image}} alt="uthapizza"> </a> <div class="media-body"> <h2 class="media-heading">{{ctrl.dish_cmnt.name}} <span class="label label-danger">{{ctrl.dish_cmnt.label}}</span> <span class="badge">{{ctrl.dish_cmnt.price | currency}}</span></h2> <p>{{ctrl.dish_cmnt.description}}</p> </div> </div> </div> <div class="col-xs-9 col-xs-offset-1"> </div> </div> </div> </body> </html>
Comments
Post a Comment