Angularjs - 获取更改后的输入范围值

问题描述 投票:0回答:1

我试图将选定的国家/地区代码传递给控制器​​内的范围变量。

<form id="call-center-form" ng-submit='submitCallForm({"telephone": number_telephone, "dial_code":dial_code})' ng-show="!submitForm">
    <input type="text" name="country_code" id="dial_code" ng-model="dial_code">
    <input name="user_phone" type="phone" value="" id="number_telephone" ng-model="number_telephone" class="user_reg_phone">
</form>
<script>
var input = document.querySelector("#number_telephone");
intlTelInput(input, {
    utilsScript: "/static/js/utils.js",
    customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) {
        var code_input = $('#dial_code')
        code_input.val(selectedCountryData.dialCode);
        console.log(selectedCountryData.dialCode)
        return "напр " + selectedCountryPlaceholder;
    },
});

app.controller('app.call-center.controller', 
    ['$scope', '$timeout', 'sendCallRequest',

    function($scope, $timeout, sendCallRequest){

        var call_code = angular.element('input[name=country_code]').val()
        $scope.dial_code = call_code

        $scope.submitCallForm = function(obj){
            $scope.submitForm = true
            $timeout(function(){
                $scope.promise = sendCallRequest.sendObject(sendUrl, obj, csrf_token)
                $scope.promise.then(function(success) {
                    return true
                }, function(err) {
                    return false
                })
                $scope.submitForm = false
            }, 1200)
        }
}]);
</script>

我发送请求后,dial_code显示一个空值,即使我做了$scope.dial_code = call_code

jquery angularjs
1个回答
0
投票
<form id="call-center-form" ng-submit='submitCallForm(formData)' ng-show="!submitForm">
    <input type="text" name="country_code" id="dial_code" ng-model="formData.dial_code">
    <input name="user_phone" type="phone" value="" id="number_telephone" ng-model="formData.number_telephone" class="user_reg_phone">
</form>

app.controller('app.call-center.controller', 
    ['$scope', '$timeout', 'sendCallRequest',

    function($scope, $timeout, sendCallRequest){




        $scope.submitCallForm = function(obj){

            $scope.submitForm = true;
            $scope.dial_code = obj.dial_code;

            $timeout(function(){
                $scope.promise = sendCallRequest.sendObject(sendUrl, obj, csrf_token)
                $scope.promise.then(function(success) {
                    return true
                }, function(err) {
                    return false
                })
                $scope.submitForm = false
            }, 1200)
        }
}]);

请检查以上代码..

© www.soinside.com 2019 - 2024. All rights reserved.