1

I'm trying to use a pickadate.js libary in my project.

What I've tried so far...

  ngAfterViewInit() {
    $('.datepicker').pickadate({
        format: 'mm/dd/yyyy',
        formatSubmit: 'mm/dd/yyyy',
        hiddenName: true
    });
  }

Gets the following error:

$(...).pickadate is not a function

I really don't want to write a td.ts for anything in my index.html:

<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My Angular2 App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- inject:css -->
  <link rel="stylesheet" href="/node_modules/pickadate/lib/themes/default.css">
  <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="/app/assets/main.css">
  <!-- endinject -->
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"> </script>
    <!-- inject:js -->
  <script src="/node_modules/pickadate/lib/legacy.js"></script>
  <script src="/node_modules/pickadate/lib/picker.time.js"></script>
  <script src="/node_modules/pickadate/lib/picker.date.js"></script>
  <script src="/node_modules/pickadate/lib/picker.js"></script>
  <!-- endinject -->

</head>
<body>

...
2
  • Where did you add the jQuery import? Script tags in templates are dropped. There are also a few questions about datepicker in Angular2 already. Did you check if they provide the info you need? Commented Feb 1, 2016 at 15:16
  • It looks like you haven't added 'pickadate' library. Commented Feb 1, 2016 at 15:16

2 Answers 2

2

Make sure you have included the TSD (right click, save as...) for jQuery into your App Component:

/// <reference path="../path/to/jquery.d.ts" />

Then also download this typing and import as so:

/// <reference path="../path/to/pickadate.d.ts" />

Lastly, make sure jQuery and PickADate are imported into your HTML. If everything is right, your code should work.

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

Comments

2

You can't add the library script tag inside a components template. <script> tags in Angular2 templates are dropped.

1 Comment

ok the fault was that i called the picker not after my jquery.js thx

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.