Ich arbeite an $ http, um Details aus einer anderen Datei mit angular js zu holen.
<body>
<h2>AngularJS</h2>
<div ng-app = "" ng-controller = "sController">
<table>
<tr>
<th>Name</th>
<th>Roll No</th>
<th>Percentage</th>
</tr>
<tr ng-repeat = "student in students">
<td>{{ student.Name }}</td>
<td>{{ student.RollNo }}</td>
<td>{{ student.Percentage }}</td>
</tr>
</table>
</div>
<script>
function studentController($scope,$http) {
var url = "C:\\Users\\Test\\Desktop\\data.txt";
$http.get(url).success(function(response) {
alert('success');
$scope.students = response;
}).error(function (response) {
alert("error");
return status;
});
}
</script>
data.txt Datei enthält die Schüler Details im JSON-Format.
[{"Name" : "Smith","RollNo" : 11,"Percentage" : "80%"}]
Die Steuerung wird nicht erfolgreich ausgeführt. Fehle ich etwas? Auch ich bekomme nichts in der Antwort. Bitte helfen Sie.
registriert haben Sie Ihren Controller? ('angular.module (moduleName) .controller ...' – AranS
Erstellen Sie ein Modul für angular und verweisen Sie den App-Namen, registrieren Sie auch den Controller mit dem App-Namen –