0

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>

Here is my controller:

(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'
        }
    ];
}

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.

5
  • 1
    Where are you assigning the controller to the view? Commented Oct 15, 2015 at 15:46
  • Also I think you are not using $scope service Commented Oct 15, 2015 at 15:47
  • I actually didn't build this project, and so new to angular that I don't completely understand how some of it works, but vm is used in place of $scope, and in all of the other pages ng-controller is not used. Even when I do at it to my page though I get the same error message. I'm sorry about my lack of knowledge. I just learned Angular and got thrown into this super big program written by someone who was a wiz with Angular and is no longer here. Commented Oct 15, 2015 at 15:49
  • This code is missing the line where you declare ng-controller and assign vm, this line would seem to be the line the error you are describing is coming from. This isn't a complete example of your code. note that the vm might be assigned in a router provider, and not in the HTML here. Commented Oct 15, 2015 at 16:37
  • 1
    either way, this error is describing report.controller as an invalid argument, but this isn't the area of the code base where report.controller is used. have you searched for report.controller in your code? Commented Oct 15, 2015 at 16:42

2 Answers 2

3

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!

Sign up to request clarification or add additional context in comments.

2 Comments

I changed it to vm.sales, still getting the same error message.
@hollyquinn - Check Edited answer for working copy of the code. Hope this will solve your problem!
2

Issues seems to be that you have the variable name as vm.sale in controller and looping thru vm.sales in html (extra s)

1 Comment

I changed this. Now I've got vm.sales in the controller and ng-repeat="sale in vm.sales" in the view. Still getting the same error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.