angular.module('myApp', ['ngRoute', 'myApp.controllers'])
.config(function ($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/views/myApp.html',
controller: 'appController'
})
.otherwise({
redirectTo: '/'
});
});
angular.module('myApp.controllers', [])
.controller('appController', function($scope, $http) {
$scope.oneCharacter = function() {
$http({
method:'GET',
url:'http://localhost:3000/#/api/info'
}).then(function(response) {
console.log('-------------------------', response);
}) .catch(function(err) {
console.log(err);
});
}
});
<div ng-controller="appController">
<input type="button" value="button" ng-click="oneCharacter()"/>
</div>
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset="utf-8" />
<title>Hello</title>
</head>
<body>
<div ng-view></div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js"></script>
<script src="app/controllers/myApp.js"></script>
<script src="app/app.js"></script>
</body>
</html>
Hallo, Ich bin eine GET-Anfrage an http://localhost:3000/#/api/info
Server sendet das ich bauen will. Ich erwarte ein json
Objekt voller Völker Informationen zurück. Jedes Mal, wenn ich auf die button
in meinem appController
(Controller) klicke, geht die Anfrage nicht die angegebene url
. Jedes Mal bekomme ich den index.html
Inhalt zurück, den ich unten kopiert habe. Allerdings habe ich es mit meinem Server postman
testen, und es gibt die richtigen Informationen zurück. Weiß jemand, warum passiert das? Dank
'http: // localhost: 3000/#/api/info' ist das gleiche wie 'http: // localhost: 3000/index.html #/api/info', Sie backed bereitstellen können versuchen, auf einem anderen Port als Ihr Frontend. –