Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 스크롤 이벤트
- Ionic modal
- scroll
- TAILWIND
- angular button
- angular route
- 앵귤러 모달
- ApexChart
- formgroup
- ajax 사용 예시
- 옵저버블
- Oracle LISTAGG 사용 예시
- Router
- prisma
- 모달
- 호버
- route
- egov spring ajax 사용 예시
- Angular Router
- modal
- 아이오닉 스크롤 이벤트
- mysql if
- 셀렉트박스 커스텀
- 스크롤 이벤트 감지
- angular modal
- flex-1
- summary
- angular animation
- 검색
- 앵귤러 애니메이션
Archives
- Today
- Total
깜놀하는 해므찌로
Angular input date set value / 앵귤러 input type date 값 셋팅 예시 본문
반응형
SMALL
<div title="일자 검색" class="flex gap-3">
<div title="시작일" class="flex gap-1 items-center">
<div class="w-12">
시작일
</div>
<input type="date" [ngModel]="startAt | date:'YYYY-MM-dd'" (input)="handleStartAt($event)" class="border rounded-md px-2 py-1 shadow">
</div>
<div title="종료일" class="flex gap-1 items-center">
<div class="w-12">
종료일
</div>
<input type="date" [ngModel]="endAt | date: 'YYYY-MM-dd'" (input)="handleEndAt($event)" class="border rounded-md px-2 py-1 shadow">
</div>
</div>
1. 템플릿 : | 파이프 연산자를 통해 날짜 포멧 설정
import { Component, EventEmitter, Output, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-datebox',
templateUrl: './datebox.component.html',
styleUrls: ['./datebox.component.scss'],
standalone: true,
imports: [
CommonModule,
FormsModule,
]
})
export class DateboxComponent implements OnInit{
@Output() searchStartAt: EventEmitter<string> = new EventEmitter<string>();
@Output() searchEndAt: EventEmitter<string> = new EventEmitter<string>();
startAt?: string | undefined;
endAt?: string | undefined;
constructor() { }
ngOnInit(): void {
let year = new Date().getFullYear();
let month = new Date().getMonth() + 1;
let date = new Date().getDate();
let past = new Date(year, month, date - 7);
this.startAt = past.getFullYear() + '-' + past.getMonth() + '-' + past.getDate();
this.endAt = new Date().toString();
}
handleStartAt(data: any){
this.searchStartAt.emit(data);
}
handleEndAt(data: any){
this.searchEndAt.emit(data);
}
}
2. 페이지 로드 시 기본 날짜 값 셋팅
npm install dayjs
import * as dayjs from 'dayjs';
startAt?: string | undefined;
endAt?: string | undefined;
this.startAt =dayjs().subtract(1, 'month').format('YYYY-MM-DD');
this.endAt = dayjs().format('YYYY-MM-DD');
3. dayjs 활용 예시
반응형
LIST
'IT' 카테고리의 다른 글
HTML Semantic tag / Angular - tailwind @apply 사용 예시 (0) | 2023.06.14 |
---|---|
Angular Kakao API Login 앵귤러 카카오 로그인 side of frontend (0) | 2023.06.14 |
tailwind 커스텀 추가 예시 (0) | 2023.06.13 |
Login Token 활용 로직 feat.jwt (0) | 2023.06.13 |
failed to apply cleanly to the shadow database. 에러 해결 Prisma migrate reset (0) | 2023.06.12 |