Получить данные из JSON в angularJS - PullRequest
0 голосов
/ 08 февраля 2019

Я новичок в AngularJS и пытаюсь получить данные из файла .json, но я не получаю их с лицевой стороны ... кто-нибудь может сказать мне, как я могу найти их на стороне клиента.Хотя я прочитал этот ответ , но не смог найти желаемый результат.

records.json

[
  {
    "firstName": "Dawn",
    "lastName" : "Cassidy",
    "gender"   : "Female",
    "salary"   : 35000
  },
  {
    "firstName": "Paul",
    "lastName": "Hastings",
    "gender": "Male",
    "salary": 325000
  },
  {
    "firstName": "steve",
    "lastName": "payne",
    "gender": "Male",
    "salary": 30000
  },
  {
    "firstName": "Tina",
    "lastName": "Duggan",
    "gender": "Female",
    "salary": 35000
  }
]

Script.js

app.controller("dataController", function ($scope, $http) {
    var url = "data/records.josn";
    $http.get(url).success(function (response) {
        $scope.employees = response;
    });
});

FirstPage.cshtml

<div ng-controller="dataController">
           <table style="width:500px; border:2px solid black;">
                <thead>
                    <tr style="text-align:left">
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Gender</th>
                        <th>Salary</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="employee in employees | orderBy: '-salary'">
                        <td>{{ employee.firstName | uppercase }}</td>
                        <td>{{ employee.lastName | lowercase }}</td>
                        <td>{{ employee.gender }}</td>
                        <td>{{ employee.salary | currency: "$" }}</td>
                    </tr>
                </tbody>
            </table>
</div>

1 Ответ

0 голосов
/ 08 февраля 2019

Синтаксическая ошибка в коде, использующем "josn" вместо "json".

app.controller("dataController", function ($scope, $http) {
    var url = "data/records.json";
    $http.get(url).success(function (response) {
        $scope.employees = response;
    });
});
...