I am trying to create light Angularjs app. I am running api server through irb cli and it is running on port 4567. When i run bundle exec ruby.rb I can confirm that there is data on the address: http://localhost:4567/api/v1/companies:
[
{"id": "1",
"name": "A"
},
{
"id": "2",
"name": "B",
}
]
I have tried with this code (hello.js):
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$scope.company=[];
$http.get("http://localhost:4567/api/v1/companies")
/*$http.get("http://localhost/fake.json")*/
.then(function(response) {
$scope.company = response.data;
});
});
HTML:
<html>
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="hello.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in company">
{{ 'name: ' + x.name + ', id:' + x.id }}
</li>
</ul>
</div>
</body>
</html>
The thing is, if I change the url to the "http://localhost/fake.json" as commented I see the data response clear. But if I use the local web server I can not see anything. Is there some kind of permissions problem or something else.