在前端显示角度JSON数组

时间:2014-11-26 18:31:08

标签: javascript json angularjs

我的数据格式如下,

        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"}]    

我试图使用

进行渲染
<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>

var timeslots = data;

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

app.controller("TimeSlotController", function($scope) {

    this.timeslot = timeslots;

});

div根据对象的数量重复但是值没有插入到视图中,为什么会这样?

这可能看起来重复了我之前的问题,但它并不完全一样,对不起,如果我重复一遍。

2 个答案:

答案 0 :(得分:0)

我认为你的代码错了..试试这个

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>

答案 1 :(得分:0)

我的问题是把手,所以我只是使用插值提供程序来解决它。

https://docs.angularjs.org/api/ng/provider/ $ interpolateProvider