I have a server set up on localhost:5000 that has a JSON string that contains "Hello world"
I want my AngularJS application to fetch this data, and display it.
here is what I have.
this is the script getJSON.js
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http({
method : "GET",
url : "localhost:5000"
}).then(function mySuccess(response) {
$scope.myWelcome = response.data;
}, function myError(response) {
$scope.myWelcome = response.statusText;
});
});
this is how I call it in my html
<div ng-app="myApp" ng-controller="myCtrl">
<p>Today's welcome message is:</p>
<h1>{{myWelcome}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("localhost:5000")
.then(function(response) {
$scope.myWelcome = response.data;
});
});
</script>
now the "myWelcome" should be "Hello world" but it just displays myWelcome when I run the code.
the backend is fully working! I've done it with regular Angular but need it to work with AngularJS unfortunately.
Any advice?