4

I am using Bootstrap 3 in the angular 2. But can't find any helpful demo or examples from online docs.

When I add time picker in the template as following:

<div class='input-group date' id='datetimepicker3'>
    <input type='text' class="form-control" #datePicker [ngModel]="f.ArrivalTime" (blur)="date = datePicker.value" />
      <span class="input-group-addon">
      <span class="glyphicon glyphicon-time"></span>
      </span>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker3').datetimepicker({
                    format: 'LT'
                });
            });
        </script>
</div>

When I click the time button, there is no response.

2
  • I don't know Bootstrap Datepicker. Where does .datetimepicker(...) come from? You might not need the $() part from my answer. Commented Jun 21, 2016 at 12:45
  • Can you please tell which version or where you get this datepicker Commented Aug 17, 2017 at 4:45

2 Answers 2

3

Script tags are removed from templates. You need to use other means to load the script.

Something like this might work (not tested)

@Component({
  selector: 'some-comp',
  template: `<div #datetimepicker></div>`
})
class SomeComp {
  @ViewChild('datetimepicker') dateTimePicker:ElementRef;
  ngAfterViewInit() {
    $(this.dateTimePicker.nativeElement).datetimepicker({format: 'LT'});
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You could use ui-bootstrap for angular 2.

It is made by the angular team I believe and they provide bootstrap directives for both angular 1 and 2.

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.