2016-06-23 9 views
0

Ich übe mit eckigen $ http für Post und Service, aber mein Problem meine Antwort-Methode sendet mir keine Daten zurück.Daten nicht in Antwort in Winkel übertragen

hier ist mein Skript für die gleiche

'use strict'; 

angular.module('confusionApp') 
     .constant("baseURL","http://localhost:8080/app/index.html#/") 
     .service('menuFactory',['$http','baseURL' function($http,baseURL) { 

      var dishes=[ 
         { 
          _id:0, 
          name:'Uthapizza', 
          image: 'images/uthapizza.png', 
          category: 'mains', 
          label:'Hot', 
          price:'4.99', 
          description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.', 
          comments: [ 
           { 
            rating:5, 
            comment:"Imagine all the eatables, living in conFusion!", 
            author:"John Lemon", 
            date:"2012-10-16T17:57:28.556094Z" 
           }, 
           { 
            rating:4, 
            comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", 
            author:"Paul McVites", 
            date:"2014-09-05T17:57:28.556094Z" 
           }, 
           { 
            rating:3, 
            comment:"Eat it, just eat it!", 
            author:"Michael Jaikishan", 
            date:"2015-02-13T17:57:28.556094Z" 
           }, 
           { 
            rating:4, 
            comment:"Ultimate, Reaching for the stars!", 
            author:"Ringo Starry", 
            date:"2013-12-02T17:57:28.556094Z" 
           }, 
           { 
            rating:2, 
            comment:"It's your birthday, we're gonna party!", 
            author:"25 Cent", 
            date:"2011-12-02T17:57:28.556094Z" 
           } 

          ] 
         }      ]; 
      var promotions = [ 
       { 
          _id:0, 
          name:'Weekend Grand Buffet', 
          image: 'images/buffet.png', 
          label:'New', 
          price:'19.99', 
          description:'Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person ', 
       } 

      ]; 

       this.getDishes = function(){ 

        return $http.get(baseURL+"dishes"); 

       }; 

       this.getDish = function (index) { 

        return $http.get(baseURL,"dishes/"+index; 
       }; 

        this.getPromotion=function(index){ 
         return promotions[index]; 
        }; 

       // implement a function named getPromotion 
       // that returns a selected promotion. 


     }]) 

     .factory('corporateFactory', function() { 

      var corpfac = {}; 

      var leadership = [ 
       { 
        name: "Peter Pan", 
        image: 'images/alberto.png', 
        designation: "Chief Epicurious Officer", 
        abbr: "CEO", 
        description: "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections." 
       }, 
       { 
        name: "Dhanasekaran Witherspoon", 
        image: 'images/alberto.png', 
        designation: "Chief Food Officer", 
        abbr: "CFO", 
        description: "Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!" 
       }     
      ]; 

     corpfac.getLeaders=function(){ 
      return leadership; 
     } 
     corpfac.getLeader=function(index){ 
      return leadership[index]; 
     } 

     return corpfac; 




     }) 

; 

controller.js

'use strict'; 

angular.module('confusionApp') 

           .controller('DishDetailController', ['$scope', '$stateParams', 'menuFactory', function($scope, $stateParams, menuFactory) { 

       menuFactory.getDish(parseInt($stateParams.id,10)); 

      $scope.dish ={}; 
      .then(
      function(response){ 
       $scope.dish=response.data; 
       $scope.showDish=true; 
      } 
      ); 

     }]) 


     .controller('IndexController',['$scope','menuFactory','corporateFactory',function($scope,menuFactory,corporateFactory){ 
      $scope.promotion=menuFactory.getPromotion(0); 
      $scope.leader= corporateFactory.getLeader(3); 

      $scope.feturedDish={}; 
      // $scope.dish = {}; 

         menuFactory.getDish(0) 
         .then(
          function(response){ 
           $scope.feturedDish = response.data; 
           $scope.showDish = true; 
           console.log($scope.feturedDish) 
          } 
         ); 
console.log($scope.feturedDish) 

     }]) 

     .controller('AboutController',['$scope','corporateFactory',function($scope,corporateFactory){ 
      $scope.leaders=corporateFactory.getLeaders(); 

     }]) 



; 

Ich bin mit tomcat 8 diese zu veröffentlichen. Ich lese, dass $ http braucht Json Daten muss ich auf diese Weise Daten senden?

Ich habe Fehler wie folgt aus:

Error====={"data":"<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.27 - Error report</title><style type=\"text/css\">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 404 - /app/index.html/dishes</h1><div class=\"line\"></div><p><b>type</b> Status report</p><p><b>message</b> <u>/app/index.html/dishes</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><hr class=\"line\"><h3>Apache Tomcat/8.0.27</h3></body></html>","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:8080/app/index.html/dishes","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"Not Found"} 
+0

menuFactory.getDish (parseInt ($ stateParams.id, 10)); $ scope.dish = {}; .Dann (sollte wahrscheinlich menuFactory.getDish (parseInt ($ stateParams.id, 10)). Dann (... und das "return $ http.get (baseURL," Dishes/"+ index;" fehlt eine Schließung) – Gregori

Antwort

0

Wo Sie Ihre Funktion (Antwort), ich würde die errorcallback hinzufügen, da eher im Ruf es ein Problem ist und Sie die Fehlermeldung ignorieren.

menuFactory.getDish(0) 
.then(
    function(response){ 
     $scope.feturedDish = response.data; 
     $scope.showDish = true; 
     console.log($scope.feturedDish) 
    }, 
    function(reason) { 
     console.log('Error: ' + JSON.stringify(reason)); 
    } 

    ); 

Tun Sie das für alle Ihre getDish Anrufe und eher Sie sollten einen Fehler sehen. Bitte poste den Fehler und wir können versuchen zu helfen.

+0

'Fehler: [$ injector: unpr] http: //errors.angularjs.org/1.5.7/$injector/unpr? P0 = baseURLProvider% 20% 3C-% 20baseURL% 20% 3C-% 20menuFactory' Ich gab der Befehl, den Sie gaben, aber sein Drucken dieses – LowCool

+0

Hmm ... Ich kann scheinen, Ihren Fehler nicht zu reproduzieren ... hier ist ein Plunker, den ich auf Ihrem Code gründete. Ich rufe 'IndexController' an und es liest 'index.html' und das Drucken dieses Inhalts in der Konsole. https://plnkr.co/edit/N829VaAUlVVZvScWoMYn?p=preview – Gregori

+0

Auch Blick auf diese $ http.get (baseURL, "Geschirr /" + Index) ... die zweite Parameter wird angenommen ein config-Objekt zu sein versuchen Sie (baseURL + 'Gerichte /' + Index) zu bekommen? – Gregori

0

Nur um zu bestätigen, werden Sie Daten zu erhalten, während diese Bar in Ihrer Adresse schlagen http://localhost:8080/app/index.html#/dishes

+0

ein Teil Mittel aktualisiert Bilder und andere Dinge sind nicht geladen, aber ich habe eine Schaltfläche konfiguriert, die Werte auf True False-Wert ändert ändert den Wert – LowCool

Verwandte Themen