0

I am trying to use bootstrap-datepicker in angular2.

                <div class="input-append date" id="datepicker">
                    <input class="span2" size="16" type="text" />
                    <span class="add-on"><i class="icon-calendar"></i></span>
                </div>





    $('#datepicker').datepicker({
        format: 'yyyy-mm-dd',
        startDate: '2001-01-01',
        autoclose: true
    }).on('changeDate', function(ev){
        this.stupid_date = ev.date;
        console.log('dudeme',ev.date.valueOf(),ev.date )
    });

How do I get the selected date? The console.log prints but the this.stupid_date is not updated.

1 Answer 1

3

Seems the this inside your callback function doesn't reference to your component instance.

Try to use arrow function as follows:

}).on('changeDate', (ev) => {
  this.stupid_date = ev.date;
  console.log('dudeme',ev.date.valueOf(),ev.date )
});

Plunker Example

See also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.