Angularjs形成不存储在数据库中的数据

时间:2016-07-08 10:18:44

标签: javascript html angularjs

我试图通过angularjs将表单数据存储到数据库中,但它不存储到数据库中。不知道我做错了什么?

我的html表单

<form  id="challenge_form" class="row" >
            <input type="text" placeholder="Challenge Name" ng-model="challengeName" />
            <select class="btn-group form-control" id="sel1" ng-model="challengeType">
                <option>-- Select Activity Type --</option>
                <option value="running">Running</option>
                <option value="walking">Walking</option>
                <option value="cycling">Cycling</option>
            </select>
            <input type="date" placeholder="Start Date" ng-model="startDate" />
            <input type="date" placeholder="End Date" ng-model="endDate" />
            <input type="button" class="btn btn-theme" ng-click="newChallenge()" value="Decide Prize">
            <input type="button" class="btn btn-theme"  value="Cancel">

        </form>

我的angularjs控制器

app.controller("NewChallengesController", ["$http", "$scope", "authenticationSvc", function ($http, $scope, authenticationSvc) {
    //alert("hello, inside New Challenge Controller");

    var token = authenticationSvc.getUserInfo();
    var config = {
        headers: {
            'h5cAuthToken': token.accessToken,
            'Accept': 'application/json;odata=verbose'
        }

    };


    $scope.newChallenge = function () {
        var data = {
            "challengeName": $scope.challengeName,
            "selectedRewardId": "283081",
            "startDate": $scope.startDate,
            "endDate": $scope.endDate,
            "activityCategoryId": 51,
            "minParticipant": 0,
            "referredNumbers": "9876543213",
            "distance": 15.0,
            "challengeType": $scope.challengeType
        };

        $http.post("http://103.19.89.152:8080/ccp-services/userchallenge/create", data, config).then(function (response) {
            alert("challenge created successfully");
        });
    };

}]);

我收到警报“挑战已成功创建”,但数据未存储到数据库中。任何帮助都非常感谢!!

1 个答案:

答案 0 :(得分:1)

例如, 请验证映射/ccp-services/userchallenge/create模型变量的请求  在您的模型中,对象名称与您在angularjs中创建的完全不同。因此,请确保模型变量名称应与UI模型变量的名称相同,然后才会绑定数据并对其进行处理。