Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在Angularjs 1.0中读取JSON文件?_Html_Angularjs_Json - Fatal编程技术网

Html 如何在Angularjs 1.0中读取JSON文件?

Html 如何在Angularjs 1.0中读取JSON文件?,html,angularjs,json,Html,Angularjs,Json,我需要读取angular 1.6中的JSON格式文件,因此我执行以下操作 Html格式的 <div ng-model="JsonRendering" ng-controller="NewsRendering"> <div ng-repeat="NewsData in News"> <h3>{{NewsData.Title}}</h3> </div> </div

我需要读取angular 1.6中的JSON格式文件,因此我执行以下操作

Html格式的

    <div ng-model="JsonRendering" ng-controller="NewsRendering">
        <div ng-repeat="NewsData in News">
            <h3>{{NewsData.Title}}</h3>
        </div>
    </div>
JSON中的

{
  "articles": [

    {
      "Title": "Article 1",

      "Abstract": "Article 1 abstract starts here ...",

      "Body": "Article 1 body starts here....."
    }
  ]
}
我试图只渲染标题,但不起作用。它显示在网页
{{NewsData.Title}


注意:json文件是文件夹中的本地json文件。所以json文件的路径是“Root/News/News.json,那么我应该如何解决这个问题呢

将其更改为,您应该使用
data.data

.controller("NewsRendering", [ "$scope", "$http", function ($scope, $http) {
        $http({
            method: 'GET',
            url: 'News/News.json'
        }).then(function success(data) {
            $scope.News = data.data;
        });
    }]);
你的重复应该是

 <div ng-repeat="NewsData in News.articles">
            <h3>{{NewsData.Title}}</h3>
 </div>

{{NewsData.Title}

$scope.News=JSON.parse(数据);打开浏览器控制台。读取错误。修复错误。然后意识到您正在尝试迭代HTTP响应,而不是迭代JSON对象的articles数组(即数据属性)使用调试器有帮助。这意味着您甚至没有启动angular应用程序。浏览器可能无法找到或加载包含您的代码的JS文件。我怀疑您没有任何错误。发布一个完整的最小示例,在一个plunkr中再现此问题。angular不解析<代码,原因只有两个>{{NewsData.Title}您在页面上看到了这样的结果:要么抛出了一个错误,要么HTML不在Angular的范围内。如果不是第一个选项,那么它就是第二个选项。您显示的代码与此无关。您确实需要显示一个演示,我们可以尝试()如果您需要帮助解决问题。正确,但这还不够。OP还需要迭代文章。(我不是向下投票者)。它在页面上显示{{NewsData.Title}}。页面上没有错误console@HTMLMan如上所述,您的应用程序似乎尚未启动。@Sajeetharan这里是我使用“ng model=JsonRendering”时遇到的问题“当您使用“ng app=”JsonRendering“时。现在它可以工作了,会有很多麻烦。@jbnite是的,看起来是这样。”
.controller("NewsRendering", [ "$scope", "$http", function ($scope, $http) {
        $http({
            method: 'GET',
            url: 'News/News.json'
        }).then(function success(data) {
            $scope.News = data.data;
        });
    }]);