Hi
I have below code . Modal should open on click of button but it already gets displayed on page.
C#
Student Portal
Add New
Student Name
Mobile No
Email
City , State , PinCode
Address
Create New Student
Modal Body...
Close
Save changesThanks

Jignesh KumarRank #91 · 22.9K reputationPosted May 2, 2024, 12:05 AM EDT
Hello Ramco,
add *ngIf for your model div
In your student component, you can add your methods to open, close and model hide property,
export class StudentComponent { isModalOpen: boolean = false; openModal() { this.isModalOpen = true; } closeModal() { this.isModalOpen = false; }Naimish MakwanaRank #324 · 7.7K reputationPosted May 2, 2024, 12:49 AM EDT
In Angular, you would typically use a component-based approach to handle modals. However, if you want to use Bootstrap modal in Angular, you can do so by using
*ngIfdirective to conditionally render the modal based on a property in your component.Here’s how you can modify your code:
First, in your component TypeScript file, define a property
showModaland a methodopenModal():showModal = false; openModal() { this.showModal = true; }Then, in your HTML, use the
*ngIfdirective to conditionally render the modal:Student Portal Add NewNow, the modal will only be displayed when
showModalistrue, which happens when you click the “Add New” button and theopenModal()method is called.Thanks