[英]Displaying angular JSON array on frontend
I have my data in the following format, 我的数据格式如下:
var data = [{"time":1,"description":"Here lies 1","cost":"10"},{"time":2,"description":"Here lies 2","cost":"20"},{"time":3,"description":"Here lies 3","cost":"10"},{"time":4,"description":"Here lies 3","cost":"10"}]
which I am trying to render using 我正在尝试使用
<div class="container">
<h3 class="text-center">Welcome to our scheduling page. Please follow the instructions to add an event to my calendar.</h3>
<div ng-app="TimeSlot">
<div class="col-md-12" ng-controller="TimeSlotController as calendar" >
<div class="col-md-5 col-md-offset-1 timeblock" ng-repeat="slots in calendar.timeslot" ng-click="">
<h3 class="event-type-name">{{slots.time}} Hour Appointment</h3>
<div class="description mts">{{slots.description}}</div>
<div class="cost">{{slots.cost }}</div>
</div>
</div>
</div>
</div>
and 和
var timeslots = data;
var app = angular.module('TimeSlot', []);
app.controller("TimeSlotController", function($scope) {
this.timeslot = timeslots;
});
The divs are repeating according to the number of objects but the values are not getting inserted into the view, why is that so ? div根据对象数重复,但是值未插入视图中,为什么呢?
This might look a repeat of my previous question but it's not exactly the same, sorry if I am repeating though. 这可能是我上一个问题的重复,但并不完全相同,但是如果我重复,很抱歉。
I think your code is wrong.. try this 我认为您的代码是错误的。
app.controller("TimeSlotController", function($scope) {
$scope.timeslot = timeslots;
});
<div ng-app="TimeSlot">
<div class="col-md-12" ng-controller="TimeSlotController" >
<div class="col-md-5 col-md-offset-1 timeblock" ng-repeat="slots in timeslot" ng-click="">
<h3 class="event-type-name">{{slots.time}} Hour Appointment</h3>
<div class="description mts">{{slots.description}}</div>
<div class="cost">{{slots.cost }}</div>
</div>
</div>
</div>
My problem was with handlebars, so I simply used the interpolate provider to fix it. 我的问题出在把手上,所以我只是使用插值提供程序来解决它。
https://docs.angularjs.org/api/ng/provider/ $interpolateProvider https://docs.angularjs.org/api/ng/provider/ $ interpolateProvider
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.