1

我已经学习 MEAN 堆栈技术一周了。我在 Angular 中使用自定义服务时遇到问题。我尝试获取一个 .json 文件,但是当应用程序加载并在 Web 检查器中检查加载的资源时,iso 文件显示了我的 index.html 文件中的代码。有谁知道为什么会发生这种情况以及如何解决?

这是定制服务:

    angular.module('StudentService', [])
        .factory('Students', ['$http', function($http) {
        return $http.get('app/students.json');
    }]);

我不明白它如何加载标题为“students.json”但在网络检查器中显示为 html 代码。任何帮助将不胜感激。

4

1 回答 1

0

像这样更改您的代码

 $http.get('app/students.json')
       .then(function(res){
          $scope.todos = res.data;                
        });
return $scope.todos;
于 2014-03-26T05:43:24.613 回答