저는 AngularJS를 배우고 있으며 인터넷의 .json 파일에서 datas를 배열로 가져 오는 데 문제가 있습니다. 이것은 상황입니다. 웹 사이트에서 api (.json)로 일부 데이터를 가져와 배열에 저장 한 다음 차트에 표시하는 html 앱을 만들어야합니다. 문제는 데이터 요청에 두 개의 값을 전달해야하므로 연결된 데이터 만받을 수 있습니다. 누군가 나를 도울 수 있습니까? 솔루션 아래 독서 JSON 파일에 대한AngularJS : .json에서 js/html로
답변
는 데 도움이 될 것입니다 - 로 간단 How to display data from a json file in angularjs?
: -
질문에 대한$timeout(function(){
dbService.getUrl('/js/udata.json').then(function(resp){
$scope.todo=resp;
});},1);
"문제는 내가 두 값을 전달할 필요가있다 내 datas 요청, 그래서 나는 그들에게 연결된 데이터 만받을 수 있습니다 "아마, 당신이 좀 더 자세한 내용을 제공 할 수있는 경우/구체적인 요구 사항을 우리가 도울 수 있습니다.
내 자바 스크립트 : - - :
여기 var todoApp= angular.module('todoApp',[]);
todoApp.factory('dbService', ['$q','$http',function ($q , $http) {
var service ={};
service.localCache = {hasdata:false,data:{},lastLoaded:new Date()};
service.getUrl = function (urlToGet,burstCache) {
var svc=this;
var deferred = $q.defer();
if ((!burstCache)&&(svc.localCache)&&(svc.localCache.hasdata)) {
console.log('resolve from local cache');
return(svc.localCache.data);
}else{
var responsePromise = $http.get(urlToGet);
responsePromise.success(function (data, status, headers, config) {
svc.localCache={};
svc.localCache.hasdata=true;
svc.localCache.data=data;
svc.localCache.lastLoaded= new Date();
deferred.resolve(data);
console.log('resolve from ajax') });
responsePromise.error(function (data, status, headers, config) {
deferred.reject({ error: "Ajax Failed", errorInfo: data }); svc.localCache={}; });
}
return (deferred.promise);
}
return service;
}]);
todoApp.controller("ToDoCtrl", ['$scope','$timeout','dbService',function($scope, $timeout, dbService)
{
$scope.todo={};
$timeout(function(){
dbService.getUrl('http://api.openweathermap.org/data/2.5/forecast/daily?lat=35&lon=139&cnt=10&mode=json',true).then(function(resp){
$scope.todo=resp;
});},1);
}]);
내 HTML입니다 : -
<body >
<div ng-controller="ToDoCtrl">
<div>
<p>City : {{todo.city.name}}</p>
<p>Country : {{todo.city.country}}</p>
<p>Population : {{todo.city.population}}</p>
<p>COD : {{todo.cod}}</p>
</div>
<table border="1">
<thead>
<tr>
<th>Dt</th>
<th>Pressure</th>
<th>Humidity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="t in todo.list">
<td>{{ t.dt }}</td>
<td>{{ t.pressure }}</td>
<td>{{ t.humidity }}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
희망
업데이트 : 여기
은 나를 위해 작동 코드입니다 이 도움이됩니다!
나는 특정 도시를 검색해야하므로 경도와 위도 값을 함수에 전달해야한다. . 링크는 다음과 같습니다. http://api.openweathermap.org/data/2.5/forecast/daily?lat=35&lon=139&cnt=10&mode=json 링크의 두 값은 전달해야하는 값입니다. – Simo
위 링크 링크의 예가 효과가 있습니다. 크로스 사이트 요청이기 때문에 귀하의 요청은 $ http.jsonp (...)입니다. 내가 당신을위한 샘플 코드를 만들어 보자. 감사합니다 – amitthk
안녕하세요, 방금 언급 한 URL에서 데이터를 표시 할 수있는 코드를 업데이트했습니다. 반환 된 데이터는 간단한 JSON이므로 JsonP를 수행 할 필요가 없습니다. 이게 도움이 되길 바란다. 그것이 도움이된다면 친절하게 대답으로 표시하십시오. 감사! – amitthk
- 1. json에서 매개 변수가있는 angularjs 필터 사용
- 2. 중첩 json에서 angularjs 템플릿의 요소 표시
- 3. NodeJS/AngularJS - JSON에서 객체 배열 읽기
- 4. JSON에서
- 5. JSON에서 jquery 또는 angularJS 옵션을 사용하여 여러 선택 만들기
- 6. AngularJS - 선택한 항목을 기반으로 JSON에서 Google maps 지시문의 범위를 변경합니다.
- 7. AngularJs - Json에서 ng-if 중첩 호출 $ http 파일
- 8. JSON에서 필터 텍스트 검색 ng-repeat가 작동하지 않습니다. angularjs
- 9. 는 JSON에서
- 10. JSON에서 가능합니까?
- 11. json에서 UiTableViewControll으로
- 12. JSON에서 Firebase까지
- 13. 문자열을 JSON에서,
- 14. AngularJS - Controller JavaScript $ http.get
- 15. 반환 개체 1 Angularjs
- 16. Angularjs 진행률 표시 구현
- 17. AngularJS parse JSON
- 18. json에서 인코딩 응답 보내기
- 19. JqGrid가 JSON에서 데이터를로드하지 않습니다
- 20. JSON에서 개체 그룹 찾기
- 21. Json에서 인수를 전달하는 방법
- 22. JSon.Net Json에서 엔티티
- 23. JSON에서 데이터베이스 데이터 캐시
- 24. JSON에서 .d는 무엇을 의미합니까?
- 25. PHP-json에서 작업하기
- 26. JSON에서 참조가 가능합니까?
- 27. json에서 여러 데이터를 복구
- 28. json에서 QT SqlQuery 반환
- 29. JSON에서 Javascript로 객체들
- 30. Fabric js JSON에서 캔버스로드
몇 가지 코드를 게시 할 수 있습니까? 나는 당신의 문제가 정확히 무엇인지 모르겠다. 당신이 필요로하는 어떤 값으로 당신의 요구에 객체를 전달할 수있다. – Kangcor