1

I'm trying to use the example shown here http://bazalt-cms.com/ng-table/example/3

Here are some snippets of it:

<table ng-table="tableParams" class="table">
        <tr ng-repeat="user in $data">
            <td data-title="'Name'" sortable="'name'">
                {{user.name}}
            </td>
            <td data-title="'Age'" sortable="'age'">
                {{user.age}}
            </td>
        </tr>
    </table>

This the data initialization at the js script:

var data = [{name: "Moroni", age: 50},
                {name: "Tiancum", age: 43},
                {name: "Jacob", age: 27},
                {name: "Nephi", age: 29},
                {name: "Enos", age: 34},
                {name: "Tiancum", age: 43},
                {name: "Jacob", age: 27},
                {name: "Nephi", age: 29},
                {name: "Enos", age: 34},
                {name: "Tiancum", age: 43},
                {name: "Jacob", age: 27},
                {name: "Nephi", age: 29},
                {name: "Enos", age: 34},
                {name: "Tiancum", age: 43},
                {name: "Jacob", age: 27},
                {name: "Nephi", age: 29},
                {name: "Enos", age: 34}]; 

There are two things I can not understand: 1. Why is there a $ sign in the ng-repeat clause? <tr ng-repeat="user in $data"> If i take the $ of, the example doesn't work.

  1. I don't understand the $defer part in the example. I tried reading the docs and view examples about what defer does and just didn't get it. How calling:

    $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    

    }

effects the scope data parameter and is it related to the fact it has a dollar sign at the html (as i mentioned at the previous question)?

omer bach
  • 2,345
  • 5
  • 30
  • 46

1 Answers1

2
  1. Name of array holding elements for table have nothing to do with with actual object exposed to $scope. You can change occurrence of 'data' in DemoCtrl and you will see it. $data is object exposed to the ng-table directive scope after resolving promise in getData method.

  2. I still have problems with $defers. Your question motivated me to fill knowledge gap:

    Promises in AngularJS and where to use them?

    AngularJS Promises - The Definitive Guide

Community
  • 1
  • 1
Teq1
  • 631
  • 1
  • 6
  • 20