[英]Error in Angular JS shows the preview as {{dish.comment}} in browser?
I am trying to do an assignment on angular .我正在尝试对 angular 进行分配。 It was working fine , then suddenly in the brackets preview , i am seeing {{dish.comment}} .
它工作正常,然后突然在括号预览中,我看到 {{dish.comment}} 。 I am a newbie.
我是新手。 Everything seems to be fine in the file though.Below is the HTML file
文件中的一切似乎都很好。 下面是 HTML 文件
<div class="row row-content" ng-controller="DishDetailController">
<div class="col-xs-12">
<div class="tab-content">
<li class="media">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-thumbnail"
ng-src={{dish.image}} alt="Uthappizza">
</a>
</div>
<div class="media-body">
<h2 class="media-heading">{{dish.name}}
<span class="label label-danger">{{dish.label}}</span>
<span class="badge">{{dish.price | currency}}</span> </h2>
<p ng-show="showDetails">{{dish.description}}</p>
</div>
</li>
</div>
</div>
</div>
Below is the App.js file下面是 App.js 文件
angular.module('confusionApp', [])
.controller('DishDetailController', ['$scope', function($scope) {
var dish={
name:'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label:'Hot',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
}
]
};
$scope.dish = dish;
}])
And i have included ng-app="confusionApp" in the HTM tag and also included scripts/app.js at the bottom我在 HTM 标签中包含了 ng-app="confusionApp" 并且还在底部包含了 scripts/app.js
angular.module('confusionApp', []) .controller('DishDetailController', ['$scope', function($scope) { var dish={ name:'Uthapizza', image: 'images/uthapizza.png', category: 'mains', label:'Hot', price:'4.99', description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.', comments: [ { rating:5, comment:"Imagine all the eatables, living in conFusion!", author:"John Lemon", date:"2012-10-16T17:57:28.556094Z" }, { rating:4, comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", author:"Paul McVites", date:"2014-09-05T17:57:28.556094Z" }, { rating:3, comment:"Eat it, just eat it!", author:"Michael Jaikishan", date:"2015-02-13T17:57:28.556094Z" }, { rating:4, comment:"Ultimate, Reaching for the stars!", author:"Ringo Starry", date:"2013-12-02T17:57:28.556094Z" }, { rating:2, comment:"It's your birthday, we're gonna party!", author:"25 Cent", date:"2011-12-02T17:57:28.556094Z" } ] }; $scope.dish = dish; }])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div class="row row-content" ng-app="confusionApp" ng-controller="DishDetailController"> <div class="col-xs-12"> <div class="tab-content"> <li class="media"> <div class="media-left media-middle"> <a href="#"> <img class="media-object img-thumbnail" ng-src={{dish.image}} alt="Uthappizza"> </a> </div> <div class="media-body"> <h2 class="media-heading">{{dish.name}} <span class="label label-danger">{{dish.label}}</span> <span class="badge">{{dish.price | currency}}</span> </h2> <span>{{dish.comments[0].comment}}</span> <p ng-show="showDetails">{{dish.description}}</p> </div> </li> </div> </div> <!--<div ng-repeat="comment in dish.comments"> <p> {{comment.comment}} </p> </div> --> </div>
See comments is array of object so you need to iterate or you can get specific value by using {{dish.comments[0].comment}}
请参阅comments 是对象数组,因此您需要迭代或使用
{{dish.comments[0].comment}}
获取特定值
I hope it will solve your problem我希望它能解决你的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.