用文本预填充角度形式

时间:2018-08-31 13:46:27

标签: html angularjs

我有一个角度形式,用于获取服务器凭据并测试与该服务器的连接。我的表单之一使用服务器的IP地址,或者我想用“ https://”预填充表单字段,或者在提交表单后将相同的字符串附加到IP值。我尝试使用ng-init="default_settings.al_address='https://'",它在页面加载时似乎可以使用,但是在页面加载完成时,该字段被清空了。这是我模板中的代码:

                    <div class="small-pad">
                        <form novalidate class="form-large">
                            <div class="form-title pad"><b>Server IP Address</b></div>
                            <input type="text" class="form" ng-value="default_settings.al_address"
                                   ng-model="default_settings.al_address"
                                   ng-change="test_al_connect_success = false; test_al_connect_fail = false"/>
                        </form>
                    </div>

                    <div class="small-pad">
                        <form novalidate class="form-large">
                            <div class="form-title pad"><b>Username</b></div>
                            <input type="text" class="form" ng-value="default_settings.al_username"
                                   ng-model="default_settings.al_username"
                                   ng-change="test_al_connect_success = false; test_al_connect_fail = false"/>
                        </form>
                    </div>

                    <div class="small-pad">
                        <form novalidate class="form-large">
                            <div class="form-title pad"><b>API Key</b></div>
                            <input type="text" class="form" ng-value="default_settings.al_api_key"
                                   ng-model="default_settings.al_api_key"
                                   ng-change="test_al_connect_success = false; test_al_connect_fail = false"/>
                        </form>
                    </div>

                    <div class="pad-button">

                        <button type="button" class='btn btn-default btn-style-blue'
                                ng-disabled="al_address=='' || al_username=='' || al_api_key==''
                                || testing_connection"
                                ng-click="btn_al_connect()">Test connection</button>
                        <img ng-if="show_al_waiting" class="waiting-gif" src="/static/images/loading.svg">
                        <i class="fas fa-check smtp_result_icon icon-green" ng-if="test_al_connect_success"></i>
                        <i class="fas fa-times smtp_result_icon icon-red" ng-if="test_al_connect_fail"></i>
                        <div class="pad-head indent" ng-if="test_al_connect_fail || test_al_connect_success">
                            //al_test_txt//
                        </div>

                    </div>

这是我的控制人:

$ scope.btn_al_connect = function(){         / *         通过服务器的“测试连接”按钮调用          * /

    // Causes loading sequence to display at front end
    _.defer(function() {
        $scope.$apply(function () {
            $scope.test_al_connect_success = false;
        });
    });
    _.defer(function () {
        $scope.$apply(function () {
            $scope.test_al_connect_fail = false;
        });
    });
    _.defer(function () {
        $scope.$apply(function () {
            $scope.show_al_waiting = true;
        });
    });
    _.defer(function () {
        $scope.$apply(function () {
            $scope.testing_connection = true;
        });
    });

    // Passes settings given by user to backend to run a connection test
    socket.emit('fe_test_connection_al',
        $scope.default_settings.al_address,
        $scope.default_settings.al_username,
        $scope.default_settings.al_api_key,
        function(al_test_output){

        _.defer(function () {
            $scope.$apply(function () {
                $scope.show_al_waiting = false;
            });
        });

        if(al_test_output[0]) {

            _.defer(function () {
                $scope.$apply(function () {
                    $scope.test_al_connect_success = true;
                });
            });
            _.defer(function () {
                $scope.$apply(function () {
                    $scope.al_test_txt = al_test_output[1];
                });
            });

        }

        else {

            _.defer(function () {
                $scope.$apply(function () {
                    $scope.test_al_connect_fail = true;
                });
            });
            _.defer(function () {
                $scope.$apply(function () {
                    $scope.al_test_txt = al_test_output[1];
                });
            });

        }

        _.defer(function () {
            $scope.$apply(function () {
                $scope.testing_connection = false;
            });
        });

    });

};

任何帮助将不胜感激!

0 个答案:

没有答案