在ng-dialog模式中保存表单数据

时间:2015-07-06 14:57:19

标签: javascript angularjs ng-dialog

所以我在角度js的ng-dialog插件中有一个表单。 ng-dialog的内容从外部html文件加载。问题是,当我尝试保存数据时,它是未定义的。我怀疑我缺少更新我使用的ng模型,但目前尚不清楚如何做到这一点。我看了一些类似的例子,但它仍然不起作用。我想在按下窗体内的按钮时收集数据,而不是在关闭对话框时收集数据,但是当关闭对话框时也是如此。这是我的代码:

angular.app.js

myApp.controller('RequestController', function ($scope, $http, $location, $window, subtitleRequestService, $sce, subtitlesApiServiceUrl, helperService, ngDialog) {

    $scope.string_identifier = helperService.getParameterByName("v");
    $scope.availableSubtitles = null;

    $scope.request = {
        status: "pending",
        status_reason: "",
        status_reason_f: ""
    };

    var getAvailableSubtitles = function()
    {
        subtitleRequestService.getAvailableSubtitlesForRequest().then(
            function (res) {
                var subs = res.data.message;
                $scope.availableSubtitles = subs;
            },
            function () {
                alert('Error');
            }
        );
    };

    $scope.saveStatus = function()
    {
        var sts = ($scope.request.status_option === "accepted" ? $scope.request.status_reason : $scope.request.status_reason_f);
        $http.post(subtitlesApiServiceUrl + "changeRequestStatus/request_id/" + $scope.string_identifier + "/status/" + $scope.request.status + "/status_reason/" + sts)
            .success(function (data, status, headers, config) {
                alert(data.message);
            }).error(function (data, status, headers, config) {
                alert(data);
            });
    };

    $scope.changeStatus = function()
    {
        getAvailableSubtitles();
        var dialogInstance = ngDialog.open({
            //appendTo: window.parent.document.getElementsByTagName('body'),
            template: "/templates/change-request-status.html",
            scope: $scope,
            controller: 'RequestController',
            className: 'ngdialog-theme-default'
        });
    };
});

externalTeamplate.html

<div class="ngdialog-message" ng-controller="RequestController">
    <h3>Schimbă status</h3>
    <div class="form">
        <form class="form" name="$scope.request">
            <div class="row">
                <label for="status_options">Status</label>
                <select name="status_options" id="status_options" ng-model="request.status_option">
                    <option value="pending" selected="selected">În procesare</option>
                    <option value="accepted">accepted</option>
                    <option value="rejected">rejected</option>
                    <option value="deleted">deleted</option>
                    <option value="in_translation">in_translation</select>
                </select>
            </div>
            <div class="row" ng-show="request.status_option !== 'accepted'">
                <label for="status_reason">Reason:</label>
                <input type="text" id="status_reason" size="35" maxlength="144" ng-model="request.status_reason" />
            </div>

            <div class="row" ng-show="request.status_option=='accepted'">
                <label for="status_reason_f">Please select:</label>
                <select id="status_reason_f" ng-repeat="(key, value) in availableSubtitles" ng-model="request.status_reason_f">
                    <option value="{{key}}">{{value}}</option>
                </select>
            </div>
        </form>
    </div>
</div>
<div class="ngdialog-buttons">
    <button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="saveStatus()">Salvează</button>
</div>

我错过了什么?谢谢!

0 个答案:

没有答案