Angular - capture datapicker value

Asked

Viewed 162 times

1

Hello, I’m having a problem in an angular application 2, I have 2 datepicker

<input type="text" data-date-format="dd/mm/yyyy" class="form-control pull-right" ng-model="ctrl.campanha.dataInicial" id="datepicker1" ng-init="initDatepicker1()">

<input type="text" data-date-format="dd/mm/yyyy" class="form-control pull-right" ng-model="ctrl.campanha.dataFinal" id="datepicke2" ng-init="initDatepicker2()">

I’m initiating them into my Controller by means of the following methods

$scope.initDatepicker1 = function () {

            $('#datepicker1').datepicker({
                autoclose: true
            })
        }

        $scope.initDatepicker2 = function () {
            $('#datepicke2').datepicker({
                autoclose: true
            })
        }
function validacoes() {


        console.log(vm.campanha.dataInicial)
        console.log(vm.campanha.dataFinal)
        return true
    }

When I try to regain the values of Datepicker through the function validacoes(), which is called by means of a ng-click they appear as Undefined, despite appearing within the input the values, see: inserir a descrição da imagem aqui

how can I solve this problem ?

  • try console.log($scope.ctrl.campanha.dataInicial); and console.log($scope.ctrl.campanha.dataFinal);

  • I just tried... result: "Undefined"

  • Good morning Matheus, the code presented by you is Angular 1, I advise you to improve your description so that other people can help you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.