0
로컬 json 파일을로드하고 $ scope 변수에 데이터를 가져 오려고합니다.
myApp.controller('myController', ['$scope', '$http', function ($scope, $http) {
$scope.menu = function() {
$http.get('file.json')
.then(function (data) {
$scope.menu=data.data.menu;
});
};
나는 또한 data.data.menu
을 반환하려고했습니다. 하지만 메뉴가 업데이트되지 않습니다.
페이지로드시이 값을 사용하려고 시도했습니다. HTML에서
$scope.menu();
:
여기 뭐가 문제<body ng-app="myApp">
<div ng-controller="myController">
<ul class="nav navbar-nav" ng-repeat="item in menu">
// other stuffs
.
나는 아래의 코드를 컨트롤러에 직접 넣었지만 여전히 작동하지 않습니다.
$http.get('file.json')
.then(function (data) {
$scope.menu=data.data.menu;
});
: 또한
, 당신은 file.json 웹 서버에서 정적 파일로 제공하고 다음과 같은 구조를 가지고 있는지 확인해야 오류가없는 것이 확실합니까? '데이터'란 무엇입니까? –
디버깅 중에 데이터를 볼 수 있습니다 – NaaN
https://stackoverflow.com/questions/16930473/angularjs-factory-http-get-json-file 아마이 같은 대답을 확인하십시오 –