【发布时间】:2016-08-21 08:00:06
【问题描述】:
我正在使用 $http 使用 Angular js 从另一个文件中获取详细信息。
<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 文件包含 json 格式的学生详细信息。
[{"Name" : "Smith","RollNo" : 11,"Percentage" : "80%"}]
控件没有进入成功。我错过了什么吗?我也没有得到任何内部回应。请帮忙。
【问题讨论】:
-
你注册你的控制器了吗? (
angular.module(moduleName).controller... -
为 Angular 创建一个模块并引用应用名称,同时使用应用名称注册控制器