【问题标题】:Angular service returning and html file instead of a json fileAngular 服务返回和 html 文件而不是 json 文件
【发布时间】:2014-03-26 05:33:21
【问题描述】:

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

这是自定义服务:

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

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

【问题讨论】:

  • 在您的快速应用程序中,您可能必须将用于加载 json 的路由添加到静态路由
  • 谢谢!我想我的快递和我的定制服务有不同的路线。这有点尴尬,但至少这个问题得到了解决。

标签: json angularjs angular-services mean-stack


【解决方案1】:

像这样改变你的代码

 $http.get('app/students.json')
       .then(function(res){
          $scope.todos = res.data;                
        });
return $scope.todos;

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2015-10-10
    • 2018-10-08
    相关资源
    最近更新 更多