0
votes

I am new in angular Other Binding is working fine but $https call is not working I got error like this when I call http call

Failed to load resource: the server responded with a status of 404 (Not Found) My Script Code is

(function(angular) {
   var myApp = angular.module("myApp", []);
   myApp.controller('myTestController', function($scope, $http) {
     $scope.firstName = "Test";
     $http.get("Students/GetStudents").success(function(response) {
       $scope.firstName = response;
     });
   });
 })(window.angular); 

My API Controller is:

[HttpGet]
public string GetStudents() {
    return "My Value";
}
1
have you verified the url/resource path is correct?Nitsan Baleli
I have One Folder as Controllers and in that i have api controller as StudentsController. when i put this url in browser it display error like: The resource cannot be found.Lalji Kanjareeya
try creating a .json file with some content, and call it from $http.get, instead of trying to call the controllerNitsan Baleli
Hi when i call this method of same controller it's working [ResponseType(typeof(Student))] public IHttpActionResult GetStudent(int id) { Student student = db.Students.Find(id); if (student == null) { return NotFound(); } return Ok(student); } sorry for poor editingLalji Kanjareeya
Don't paste code into a comment. Edit your question.user1907906

1 Answers

0
votes

In Api Controller: [HttpGet] [Route("getStudents")] public string GetStudents() { return "My Value"; }

And in angular: change "Students/GetStudents" for "Students/getStudents"