-1

for the need of a future post, I need to make work the following stackblitz example. But nothing appear: https://stackblitz.com/edit/angular-ivy-nzt8oc?file=src%2Fapp%2Fapp.component.html

flamant
  • 733
  • 4
  • 15
  • 41
  • Simply declaring `$` wont work. You need to `import * as $ from 'jquery';` –  Jun 10 '20 at 10:52

1 Answers1

0

Please see the documentantion.
Simply use:

import { Component, VERSION, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import $ from 'jquery';
import datepickerFactory from 'jquery-datepicker';

datepickerFactory($);

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
  name = 'Angular ' + VERSION.major;

  public dialogFormGroup: FormGroup;

  constructor(private formBuilder: FormBuilder){}

  ngOnInit() {
    this.dialogFormGroup = this.formBuilder.group({
      creditTerminationDate: ['', Validators.required]
    });
    let that = this;
    $( "#datepicker" ).datepicker({
            dateFormat: "dd/mm/yy",
            onSelect: function (dateText) {
              that.dialogFormGroup.get('creditTerminationDate').setValue(dateText);
              that.dialogFormGroup.get('creditTerminationDate').markAsTouched();
              that.dialogFormGroup.get('creditTerminationDate').updateValueAndValidity();              
              console.log('creditTerminationDate validity');
              console.log(that.dialogFormGroup.get('creditTerminationDate').valid);

            }
        });
  }  
}
nickbullock
  • 6,424
  • 9
  • 27
  • first stackblitz indicate that it cannot find module jquery and jquery-datepicker despite I added it as depency, second, it still does not work. Why did you rate down my question ? – flamant Jun 10 '20 at 13:45