각도 1.6의 JSON 형식 파일을 읽어야하므로 다음을 수행합니다.
HTML에서
<div ng-model="JsonRendering" ng-controller="NewsRendering">
<div ng-repeat="NewsData in News">
<h3>{{NewsData.Title}}</h3>
</div>
</div>
스크립트에서
angular
.module( "JsonRendering", [])
.controller("NewsRendering", [ "$scope", "$http", function ($scope, $http) {
$http({
method: 'GET',
url: 'News/News.json'
}).then(function success(data) {
$scope.News = data;
});
}]);
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;
});
}]);
그리고 당신의 ng-repeat는,
<div ng-repeat="NewsData in News.articles">
<h3>{{NewsData.Title}}</h3>
</div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다