tobmes
Goto Top

Angular Daten an localhost senden

Hi Experten,

ich befasse mich gerade etwas mit AngularJS und habe jetzt ein kleines Problem mit dem absenden von Daten. Hier mal ein paar Code-Auszüge:

app.js:
ngular.module('AngularApp', ['ngAnimate', 'ngRoute'])  
/*
 getItems: gibt alle Artikel zurück
 addArticle: nimmt ein objekt entgegen und fügt es dem "Warenkorb"(items) hinzu 
 sum: Berechnet die Summe der Pizzen im Warenkorb
 */
    .config(function ($routeProvider) {
        $routeProvider
            .when('/', {templateUrl: 'articles.html'})  
            .when('/about', {template: 'Über unsere Pizzeria'})  
            .otherwise({redirectTo: '/'});  
    })<snip>
.controller('SendDataCtrl', function ($scope, $http) {  
        var url = 'localhost';  
        var Data = 'Test';  
        $scope.sendData = function () {
            $http({
                method: 'POST',  
                url: 'localhost:63342',  
                data: 'Test',  
                headers: {'Content-Type' : 'application/x-www-form-urlencoded'}  
            }).error(function (response) {
                console.log(response);
            });
        }
    });

und hier mal der HTML Teil:
<div ng-controller="sendDataCtrl">  
                    <a href ng-show="cart.getItems().length" class="btn btn-success glyphicon glyphicon-shopping-cart"  
                       ng-click="sendData();"> Bestellen</a>  
                    </div>

Bei Aufrufen der Seite erhalte ich dann im Log schon einer Fehlermeldung
Error: [ng:areq] Argument 'sendDataCtrl' is not a function, got undefined

Leider habe ich keine Ahnung, was das Problem ist. Kann mir da evtl. jemand helfen?

Content-Key: 329995

Url: https://administrator.de/contentid/329995

Printed on: April 16, 2024 at 19:04 o'clock

Mitglied: 132272
132272 Feb 20, 2017 updated at 12:38:38 (UTC)
Goto Top
Hi,
kenne zwar AngularJS jetzt nicht, aber normalerweise ist JavaScript ja "case-sensitive", deswegen würde ich das als erstes im JS und HTML angleichen:

sendDataCtrl => SendDataCtrl

Gruß