Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Unable to recover my webServices in AngularJS

Unable to recover my webServices in AngularJS

Scheduled Pinned Locked Moved Windows API
javascripthelphtmlcomtools
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11139908
    wrote on last edited by
    #1

    Hello everybody, I'm writing you because I have a problem that blocks me in advancing of my project since few days. I created a WebApi which is recovered by my AngularJs module. Here is my controller in my WebAPI :

    namespace API.Controllers
    {
    public class questionsController : ApiController
    {
    public static Lazy> questions = new Lazy>();
    public static Question question = new Question();
    public int pageLoad = 0;
    public questionsController()
    {

            questions.Value.Add(new Question { id = 1, libelle = "tettettetetetet" });
            questions.Value.Add(new Question { id = 2, libelle = "poiuyterz" });
            questions.Value.Add(new Question { id = 3, libelle = "udeuhdue" });
             
          }
      // GET: questions
        public List GetQuestions()
        {
             
            return questions.Value;
            
        }
    
      // GET : questions/2
        public IHttpActionResult getQuestion(int id)
        {
            question = questions.Value.First((p) => p.id == id);
            return Ok(question);
        }
    

    When I test this service in my browser browser (localhost: .... / api / questions), I have questions who appear in XML format. However I can't seem to call these data in an HTML page with Angular Js module. Here is my HTML code:

    <html ng-app>
    <head>
    <title>Questions</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script>
    <script src="questionsController.js"></script>
    </head>
    <body>

    ID : {{ question.id }}

    libelle : {{ question.libelle }}

        id {{ questions.id }} !
          
        libelle {{ questions.libelle }} !
    

    </body>
    </html>

    Here is my Angular JS code :

    function toto($scope, $http) {
    $http.get('http://localhost:57709/api/questions/3').success(function (data) {
    $scope.questions = data;
    })
    .error(function () {
    $scope.error = "An Error has occured while loading posts!";
    $scope.loading = false;
    });
    }

    Here is the error that my browser returns m

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups