How to establish a null value in a primeng pcalendar

I'm facing an issue with a p-calendar in a priming theme using Angular 2. I am trying to clear the calendar value once a user selects a date and set it to a blank value. Here's my code:

Component

<div style="margin-right: -6px"> 
     <p-calendar [(ngModel)]="viewModel.fromDate" [showIcon]="true" readOnlyInputText="true" (click)="restoreValues()"></p-calendar>
</div>

TypeScript file

export class RequestSearcherComponent implements OnInit {


restoreValues(): void {

    this.viewModel.areaIds = [];
    this.viewModel.cedingIds = [];
    this.viewModel.requestType = [];
    this.viewModel.requestResponsible = [];
    this.viewModel.requestStatus = [];
    this.fromDate.setDate(null);
   }
}

I've tried various methods and approaches like the setDate method mentioned in the code. But unfortunately, none of them seem to work :(

Any help would be greatly appreciated!

Thank you in advance.

Answer №1

Issue Resolved!

It may not be the most efficient method, but it gets the job done...

Widget Component

<section>
     <date-picker #selectDate [(ngModel)]="selectedDate" [showIcon]="true" readOnlyInputText="true"></date-picker>
</section>   

Angular Module

@NgModule({
imports: [
    BrowserModule,
    FormsModule
],
declarations: [
    RequestSearcherComponent
    ]
})
export class RequestSearcherModule { }

@Component({
selector: 'app-request-searcher',
templateUrl: './request-searcher.component.html'
})
export class RequestSearcherComponent implements OnInit {

@ViewChild('selectDate') dateSelector: DatePicker;

/** Custom functionality... */

resetSelections(): void {
    this.dateSelector.selectedDate = null;
    this.dateSelector.updateInputField();
   }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using ReactJS to pass an arrow function as a prop

Hey, I'm currently facing an issue where I need help creating a React component that can accept the following custom transformation: <CustomComponent transform={e=> {...e, text = e.text.toUpperCase()}}> </CustomComponent> I would real ...

What is the best method for retrieving information from a Java REST API using Angular 7?

view image descriptionaccess this API link here Can someone explain the process of retrieving data from this api? ...

Learn the proper way to specify the return type of a function as a class, rather than an instance, in Typescript

Is there a way to declare that a function returns a generic class definition? I have tried the following for non-generic classes, but it does not work for generic ones: export function composeAll(composeFunction: Function, depsFunction: Function): (compon ...

Using React to display an HTTP response containing text or HTML content

I am currently developing an application that allows users to upload an .xls file to a server, and in return, they receive a text/html response. I am looking for a way to preview this response in a similar manner to what is seen in developer tools. Here is ...

Ways to leverage Composite API in place of Mixin or Extends functionality

Currently, I am exploring the use of Vue3 for my project. One issue I am facing is that I need to create multiple components (SFC) with similar properties. I want to define these common properties using the composite API across all components, like so: con ...

The module '@/assets/icons/pay/pay-success.png' cannot be located, along with its corresponding type declarations.ts

Recently, I encountered an issue while trying to import a png image in my Typescript code. Here is the snippet of code that caused the error: import paySuccessIcon from "@/assets/icons/pay/pay-success.png"; When I tried to import the image, Visual Studio ...

For Angular 4, simply add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of the component in order to permit any element

After using angular-cli to create a new project (ng new my-project-name), I ran npm run test successfully without any issues. To display font icons in my project, I added the Font Awesome module from https://www.npmjs.com/package/angular-font-awesome. In ...

What is the process for defining functions with distinct data types while allowing variables to have multiple data types?

I am facing a declaration issue - or rather, a challenge in comprehending Typescript. Let me illustrate the scenario: public migrationSource: Skater | Rink; public migrationDestination: Skater | Rink; public migrationMode: MigrationMode; ngOnInit() { ...

Angular 10 recommends utilizing the "forEach" method in place of "map" since the return value of "map" is not being utilized in this specific context

I encountered the following error message: Consider utilizing "forEach" instead of "map" since the return value is not being utilized in this case. declare const require: { context(path: string, deep?: boolean, filter?: RegExp): { keys(): string[]; (id: ...

How can you consistently emphasize data points in a line chart using NGRX?

I'm currently working with a line chart that displays line series. Is there any way to ensure all data points are highlighted at all times? Right now, the only time a data point is highlighted is when the mouse hovers over it. <ngx-charts-line ...

Angular 5 - Keeping track of variable updates

I've searched various topics on this issue, but none seem to address my specific problem. I need a way to detect changes in the properties of a component without having to convert the variable into an array or iterable. I tried using Subject, but coul ...

Loop through a collection of elements of a certain kind and selectively transfer only certain items to a different collection of a different kind

When working with typescript, I am faced with the challenge of dealing with two arrays: interface IFirst{ name: string; age: number } interface ISecond { nickName: string; lastName: string; } myFirstArray: IFirst[]; mySecondArray: ISe ...

Automate your builds with Github actions for both tags and branches!

In my typescript project repository, our release policy states that we publish packages from the master branch to the next npm tag. Additionally, we have a dedicated branch called release for publishing to the latest npm tag. My goal is to optimize the sol ...

Angular is not providing the anticipated outcome

I'm new to Angular (7) and I'm encountering an issue while trying to retrieve the status code from an HTTP request. Here's the code snippet used in a service : checkIfSymbolExists() { return this.http.get(this.url, { observe: 'res ...

Is it possible for the navigator to provide the language or languages used in Angular Universal?

I am curious about the use of navigator in code that is meant to run on the server, as navigator is typically used in browser environments. In a codebase at work, I came across the following snippet: navigator.language.slice(0, 2); Interestingly, we are u ...

Using Typescript in NextJS 13 application router, implement asynchronous fetching with async/await

Recently, I implemented a fetch feature using TypeScript for my NextJS 13 project. As I am still getting familiar with TypeScript, I wanted to double-check if my approach is correct and if there are any potential oversights. Here is the code snippet from ...

Encountering ng build --prod errors following Angular2 to Angular4 upgrade

Upon completing the upgrade of my Angular2 project to Angular4 by executing the following command: npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @an ...

Is there a way to turn off tsc pretty printing using the configuration file?

My typescript program is intentionally broken but I want to fix it. 12:17:23:~/hello $ cat hello.ts console.log("Hello World" 12:17:29:~/hello $ cat package.json { "dependencies": { "typescript": "^5.2.2" ...

How is it that the callback method in the subscribe function of the root component gets triggered every time I navigate between different pages within the application?

I am currently using Angular 10 and have developed a server that returns an observable: export class CountrySelectionService { private _activeCountry = new BehaviorSubject(this.getCountries()[0]); public getActiveCountryPush(): Observable<CountryS ...

Step-by-step guide to creating a dropdown menu within a form element, with a variety of selectable values generated in

I am dealing with an array of employees who are assigned tests by a Lead. When tests are being assigned, the selected employee is allocated correctly. Upon review, the Lead can easily see which test is assigned to each employee. However, when the table is ...