AngularJS ng-repeat不起作用 [英] AngularJS ng-repeat not working
本文介绍了AngularJS ng-repeat不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要通过ng-repeat访问的数据表.我认为代码中的所有内容都正确,但是当我加载页面时,数据不会加载.我不确定自己在做什么错.这是我的桌子:
Hi I have a table of data that I'm trying to access via ng-repeat. I think I've got everything correct in my code, but when I load the page the data doesn't load. I'm not sure what I'm doing wrong. Here is my table:
<table class="table table-bordered table-hover table-responsive"
ng-repeat="sale in vm.sales">
<thead>
<tr>
<th>
Date Ordered
</th>
<th>
Retail
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{{ sale.dateOrdered }}
</td>
<td>
{{ sale.firstLoadRetail}}
</td>
</tr>
<tr>
<th>
Subtotal
</th>
</tr>
</tbody>
这是我的控制人:
(function () {
'use strict';
angular
.module('crm.ma')
.controller('ReportCtrl', ReportCtrl);
function ReportCtrl() {
var vm = this;
vm.sale = [
{
dateOrdered: '05/10/2015',
firstLoadRetail: '75',
firstLoadCost: '65',
instantProfitAirTime: '9',
instantProfitSpiff: '59',
netRetail: '75',
netCost: '7',
netProfit: '67',
count: '0',
billAmount: '45'
},
{
dateOrdered: '06/22/2015',
firstLoadRetail: '85',
firstLoadCost: '75',
instantProfitAirTime: '10',
instantProfitSpiff: '86',
netRetail: '22',
netCost: '8',
netProfit: '22',
count: '0',
billAmount: '35'
}
];
}
我收到错误消息参数'report.controller'不是一个函数,未定义.上次收到此错误消息时,我有一个错字,但是这次我的代码中没有看到任何错字.
I'm getting the error message Argument 'report.controller' is not a function, got undefined. Last time I got this error message I had a typo, but I'm not seeing any typos in my code this time.
推荐答案
在下面的工作代码段中进行检查-
check below working code snippet -
angular
.module('myApp',[])
.controller('myCtrl', ['$scope', function($scope){
$scope.sales = [
{
dateOrdered: '05/10/2015',
firstLoadRetail: '75',
firstLoadCost: '65',
instantProfitAirTime: '9',
instantProfitSpiff: '59',
netRetail: '75',
netCost: '7',
netProfit: '67',
count: '0',
billAmount: '45'
},
{
dateOrdered: '06/22/2015',
firstLoadRetail: '85',
firstLoadCost: '75',
instantProfitAirTime: '10',
instantProfitSpiff: '86',
netRetail: '22',
netCost: '8',
netProfit: '22',
count: '0',
billAmount: '35'
}
];
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="myCtrl">
<table class="table table-bordered table-hover table-responsive" ng-repeat="sale in sales">
<thead>
<tr>
<th>
Date Ordered
</th>
<th>
Retail
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{{ sale.dateOrdered }}
</td>
<td>
{{ sale.firstLoadRetail}}
</td>
</tr>
<tr>
<th>
Subtotal
</th>
</tr>
</tbody>
</div>
</div>
希望这可以解决您的问题!
Hope this will solve you problem!
这篇关于AngularJS ng-repeat不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文