Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with Angular 2+ #120

Open
akildemir opened this issue Jun 26, 2020 · 1 comment
Open

Usage with Angular 2+ #120

akildemir opened this issue Jun 26, 2020 · 1 comment

Comments

@akildemir
Copy link

akildemir commented Jun 26, 2020

hello, I have been trying to use this plugin with angular 6. I have a calendar logo and want to show the calendar on click. I have an input tag in the component that I want to show it and I'm assigning the calendar to this input that from the component's ts file. I'm calling the datepicker.open()from a function in the ts file. The calendar opens no problem here but it doesn't open in the input that I have assigned, instead it inserts the html at the end of the body tag in the ìndex.htmlfile. Also there is no css being assigned to it. Just raw html. Here is my ts file:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import TinyDatePicker from 'tiny-date-picker';

@Component({
  selector: 'example',
  templateUrl: './example.component.html',
  styleUrls: ['./example.component.css']
})
export class ExampleComponent implements OnInit {

  dp: any;

  constructor() {}
 
   ngOnInit() {
        this.dp = TinyDatePicker(document.getElementById('tinyDatePicker'));
  }

 openDateBox(){
    this.dp.open();
  }

And here is my example.component.html,


<div class="col-sm">
          <label for="Date"><b>Date: </b></label>
          <div (click)="openDateBox()" style="width: 30px; height: 30px; display: inline-block; margin-left: 20px;">
                <img src=".path/to/some_image.jpg" style="width: 100%; height: 100%;" alt="">
          </div>
          <div style="width: 80px; height: 80px;" >
                <input type="text" id="tinyDatePicker" hidden='true'>
         </div>
</div>

Here is how my component looks before click:

https://imgur.com/a/b4U19PR

And this is after click to calendar logo:

https://imgur.com/a/QUnAqCA

What am I doing wrong or missing?

@machadodev
Copy link

Hey man, how's it going?

I had the same problem.

You have to import tiny date picker css.

In VueJS you can solve like this:

Screenshot from 2021-03-16 15-37-00

Or like this:

Screenshot from 2021-03-16 15-38-16

And this is the result:

Screenshot from 2021-03-16 15-38-07

You just have to adjust it to angular.
Hope it helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants