-3
調用從服務器的數據在我的應用程序離子我能夠從.factory爲我的數據,但我想從服務器(JSON)得到我的數據,我已經嘗試了很多代碼已經但未能解決問題。請建議我在services.js文件中寫一個代碼,以便我可以從http://localhost:3000/statments獲取我的數據。
看一看上面的維修代碼,看看我從services.js獲取我的數據
調用從服務器的數據在我的應用程序離子我能夠從.factory爲我的數據,但我想從服務器(JSON)得到我的數據,我已經嘗試了很多代碼已經但未能解決問題。請建議我在services.js文件中寫一個代碼,以便我可以從http://localhost:3000/statments獲取我的數據。
看一看上面的維修代碼,看看我從services.js獲取我的數據
//controller
app.controller('YourControllerName', YourControllerName);
function YourControllerName($scope, myService) {
$scope.fetchData = function() {
myService.getData().then(function(result) {
console.log(result.data);
});
}
};
//service.js
app.service("myService", function ($http) {
this.getData = function() {
return $http.get('http://localhost:3000/');
}
});