The Bootstrap modal I implemented is opening correctly, but for some reason, the form inside is not appearing

I created the AddJokeModalComponent to streamline the process of opening a form without duplicating code in every component. Below is the modal structure:

<ng-template #addJokeModal>
   <div class="modal-content my-custom-modal">
        <div class="modal-header">
            <h4 class="modal-title pull-left">Dodawanie żartu</h4>
            <button type="button" class="btn-close close pull-right" aria-label="Close" (click)="modalRef?.hide()">
                <span aria-hidden="true" class="visually-hidden">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <div class="adding-joke" *ngIf="!isloading">
                <form method="POST" [formGroup]="addJokeForm" (ngSubmit)="addJoke()">
                    <div class="joke-category">
                        <select name="group" class="custom-select" formControlName="category">
                            <option value="" disabled selected hidden>Wybierz kategorię</option>
                            <option *ngFor="let category of categories">{{ category.name }}</option>
                        </select>
                    </div>
                    <div class="joke-content">
                        <input placeholder="Wprowadź treść" type="text" class="form-control" formControlName="content">
                    </div>
                    <div class="cancel-joke">
                        <button class="cancel-button" (click)="cancelJoke()">Anuluj</button>
                    </div>
                    <div class="add-joke">
                        <button class="add-button" id="add_joke_button">
                            Dodaj
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</ng-template>

Here's the corresponding TypeScript code:

 import { Component, OnInit, TemplateRef, VERSION } from '@angular/core';
import { PagesService } from '../pages.service';
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-add-joke-modal',
  templateUrl: './add-joke-modal.component.html',
  styleUrls: ['./add-joke-modal.component.css']
})
export class AddJokeModalComponent {

  public jokes: any = [];
  isLoading = true
  modalRef?: BsModalRef;
  public categories: any = [];
  public isloading = true;
  addJokeForm!: FormGroup;
  get addJokeF() { return this.addJokeForm.controls; }
  constructor(
    private PagesService: PagesService,
    private modalService: BsModalService,
    private formBuilder: FormBuilder,
    private router: Router,
  ) { }

  ngOnInit(): void {
    this.addJokeForm = this.formBuilder.group({
      category: ['', Validators.required],
      content: ['', Validators.required],
    });
    this.isloading = false;
    this.loadCategories();
  }

openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template);
  }
  addJoke() {
    if (this.addJokeForm.invalid) {
      return;
    } else {
      const json_data = {
        category: this.addJokeF['category'].value,
        content: this.addJokeF['content'].value,
      }
      this.PagesService.AddJoke(json_data).subscribe(response => {
        {
          this.router.navigate(['../home']);
        }
      })
    }
  }
  loadCategories() {
    this.PagesService.LoadCategories().subscribe(response => {
      this.categories = response
      console.log(response)
    })
  }
  cancelJoke() {
    this.modalRef?.hide();
}

}

Another component using the modal:

 <button class="add" (click)="openModal(addJokeModal)">Dodaj</button>

<ng-template #addJokeModal>
  <app-add-joke-modal></app-add-joke-modal>
</ng-template>

<div class="jokes">
  <div class="col-lg-6 col-sm-12 joke" *ngFor="let joke of jokes">
    <div class="category">
      {{joke.category}}
    </div>
    <div class="conent">
      {{joke.content}}
    </div>
    <button class="delete" (click)="deleteJoke(joke.id)">Usuń</button>
  </div>
</div>

When clicking on the "add" button, only a small strip appears instead of the entire modal with the form. The 'AddJokeModal' component has been added to app.module.ts in the declarations section. No errors are shown in the console. Any assistance would be appreciated.

Answer №1

Perhaps removing the redundant isLoading variable and using only isLoading throughout your code would help.

public isloading = true;

https://i.sstatic.net/CtLMV.png

If that doesn't resolve the issue, consider removing

*ngIf="!isloading" 

from the modal body code temporarily for testing purposes to pinpoint where its value is being updated.

https://i.sstatic.net/2jyqS.png

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

Exploring Angular 2: Incorporating multiple HTML pages into a single component

I am currently learning Angular 2 and have a component called Register. Within this single component, I have five different HTML pages. Is it possible to have multiple templates per component in order to navigate between these pages? How can I implement ro ...

Validation Form Controls

Here is a piece of code that works for me: this.BridgeForm = this.formBuilder.group({ gateway: ["", [Validators.required, Validators.pattern(this.ipRegex)]], }); However, I would like to provide more detail about the properties: this.BridgeF ...

Is there a method to implement retries for inconsistent tests with jest-puppeteer?

Currently, I am struggling with an issue where there is no built-in method to retry flaky tests in Jest. My tech stack includes Jest + TypeScript + Puppeteer. Has anyone else encountered this problem or have any suggestions for possible solutions? I attem ...

What is the process for setting up a node test launch configuration?

I have some "node 18 test runner" tests ready to be executed. I can run them using the following command: node --loader tsx --test tests/**/*.ts To debug these tests in vscode, I realized that I need to set up a configuration entry in my launch.json. But ...

Techniques for concealing a button when the "disabled" attribute is set to "true"

The button is currently disabled, however, I intended for it to be hidden from the UI when the disabled condition is met - <button ion-button block class="button-color-blue" [disabled]="true" (click)="closePage()"> Cancel </b ...

The Angular framework may have trouble detecting changes made from global window functions

While working, I came across a very peculiar behavior. Here is the link to a similar issue: stackblitz In the index.html file, I triggered a click event. function createClause(event) { Office.context.document.getSelectedDataAsync( Office.Coerci ...

Experiencing difficulties while running the npm internationalize command

Package Details { "name": "m.zbor.md", "version": "1.0.0", "description": "Mobile version of Zbor.md website", // more package details... } Typescript Configuration { "compilerOptions": { "target": "es5", "module": "commonjs", // m ...

Leveraging WebWorkers in Typescript alongside Webpack and worker-loader without the need for custom loader strings

I've been trying to implement web workers with Typescript and Webpack's worker-loader smoothly. The documentation shows an example of achieving this using a custom module declaration, but it requires the webpack syntax worker-loader!./myWorker. ...

Problem with Angular app not loading in IE 11 due to ES6 targeting

I have encountered an issue while developing a new application with IE11 as the target browser. When I set the target to es6, the app fails to load and displays the error shown below. https://i.stack.imgur.com/FL8BG.png However, when I switch the target ...

What is causing the md-menu options to not be injected into my hybrid Angular application?

I am currently troubleshooting an issue in my hybrid Angular/AngularJS application that arises upon reloading. To see a demonstration of this issue, visit this StackBlitz link. The approach I am using to bootstrap AngularJS within an Angular app is largely ...

Exploring the Differences between Angular's Http Module and the Fetch API

While I grasp the process Angular uses for HTTP requests, I find myself leaning towards utilizing the Fetch API instead. It eliminates the need to subscribe and unsubscribe just for a single request, making it more straightforward. When I integrated it int ...

Error in Angular 5: Google Maps not defined

Having trouble implementing Google Maps on my Angular 5 app. Upon loading the view, I am encountering this error in the JavaScript console: LoginComponent_Host.ngfactory.js? [sm]:1 ERROR ReferenceError: google is not defined at LoginComponent.ngAfterVie ...

How can I access a nested FormArray in Angular?

I have a situation where I am trying to access the second FormArray inside another FormArray. Here is an excerpt from my component: registrationForm = new FormGroup({ registrations: new FormArray([this.patchRegistrationValues()]) }); patchRegistrati ...

Issue encountered while trying to install Angular2 using NPM

My attempts to install Angular2 through Terminal have been met with some errors. I have verified that Node and NPM are both current. Screenshot of the Terminal As a newcomer, any assistance would be greatly appreciated. Thank you, Spen ...

Creating a concise TypeScript declaration file for an established JavaScript library

I'm interested in utilizing the neat-csv library, however, I have encountered an issue with it not having a typescript definition file available. Various blogs suggest creating a basic definition file as a starting point: declare var neatCsv: any; M ...

Error: The default export is not a component compatible with React in the specified page: "/"

I'm facing an issue while building my next app. Despite using export default, I keep encountering an error that others have mentioned as well. My aim is to create a wrapper for my pages in order to incorporate elements like navigation and footer. vi ...

Error: The absence of an element identified by the locator does not cause the protractor spec to fail, but rather it executes successfully

This automation framework follows the page object model and utilizes the async/await approach rather than promises. TypeScript is used, with compilation to JavaScript (protractor) for script execution. Page Object: async addProjectDetails(): Promise< ...

Using RxJS to merge various HTTP requests into a unified and flattened observable array

Struggling with combining multiple http get requests simultaneously and returning them as a unified, observable array. In my current setup, the method returnNewCars() retrieves Observable<ICar[]> by executing a single http get request. However, in t ...

Creating a cutting-edge object using Angular 4 class - The power of dynamism

Attempting to create a dynamic object within a function, but encountering recognition issues. function1(object: object) { return new object(); } The function is invoked as follows: function1(Test) 'Test' represents a basic Class implementatio ...

Implementing binding of JSON API responses to dropdown menus in Angular 4

In my current Angular 4 application, I am faced with the challenge of populating a dropdown menu with data from an API response. Specifically, I am struggling to retrieve the necessary information for each section from the API. The API provides data on C ...