Issue with the close button on ngb-alert not functioning properly

As I develop my website, I have incorporated an ngb-alert component to display an alert message to users upon login. While the alert itself is functioning properly, I have encountered an issue with the close button being misaligned, and I am struggling to troubleshoot it.

Below are snippets of the code I am currently working with:

**HTML COMPONENT**

<span>
    <ngb-alert type="primary" (close)="close()" [dismissible]="dismissible"> {{errorMessage}}</ngb-alert>
</span>


**TYPESCRIPT COMPONENT**

import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-ngbd-error-message',
  templateUrl: './error-message.component.html',
  styleUrls: ['./error-message.component.less']
})

export class NgbdErrorMessageComponent {
  @Input() errorMessage: string;
  @Input() close: () => void;
  @Input() dismissible = true;
}

**LESS STYLING**
@import url('../../../global-less/color-variables.less');

:host {
  width: 100%;
  height: 100%;
}
:host .alert {
  margin: 0;
}
:host .alert-dismissible .close {
  padding: .6rem 1rem;
}

The class assigned to the button within the ngb-alert appears to be btn-close. Here is the HTML element rendered on the webpage:

<ngb-alert _ngcontent-ng-c2763413438="" role="alert" type="primary" ng-reflect-type="primary" ng-reflect-dismissible="true" class="alert alert-primary show fade alert-dismissible">Amidst a cascade of sparkling emerald leaves, the whimsical hedgehog orchestrated a symphony with a violin.<button type="button" aria-label="Close" class="btn-close"></button><!--bindings={ "ng-reflect-ng-if": "true" }--></ngb-alert>

Here are the applied styles in sequence:

First Image of Styles

Second Image of Styles

See how it appears on the actual webpage:

Screenshot of Component

My current setup includes:

  • Angular - 16.2.2

  • NGBootstrap - 15.0.1

I have investigated possible reasons for the issue, such as:

  1. Conflicting Styles
  2. Incompatible ngbootstrap Version
  3. Missing Dependencies

Answer №1

The term "Output" in ngb-alert is shown as "closed" instead of "close"

<ngb-alert type="primary"
           (closed)="close()"
           [dismissible]="dismissible">
   {{errorMessage}}
</ngb-alert>

By the way, you can utilize an @Input in your parent component like this:

//In parent
    <app-ngbd-error-message errorMessage='hi, error' [close]="close">
       </app-ngbd-error-message>

  close()
  {
    console.log("hi")
  }

You have the option to use @Output in your component:

//Your component
  @Output() close:EventEmitter<void>=new EventEmitter<void>()

<ngb-alert type="primary" (closed)="close.emit()" [dismissible]="dismissible"> 
           {{errorMessage}}
</ngb-alert>

//And in your parent

<app-ngbd-error-message errorMessage='hi, error' 
       (close)="close()">
</app-ngbd-error-message>

Remember: Ensure that you include the bootstrap.min.css in your .css file

Here is a stackblitz link

Update: The close button should have the class "btn-close", as defined in boostrap.min.css. You can also find this information on the Bootstrap website.

.btn-close:hover {
    color: #000;
    text-decoration: none;
    opacity: .75;
}
.alert-dismissible .btn-close {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    padding: 1.25rem 1rem;
}
.btn-close {
    box-sizing: content-box;
    width: 1em;
    height: 1em;
    padding: .25em;
    color: #000;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
    border: 0;
    border-radius: .375rem;
    opacity: .5;
}

Answer №2

After upgrading the Bootstrap version in my project, I was able to solve the issues I was facing. It turns out that the discrepancies between my ng-bootstrap and Bootstrap versions were causing conflicts.

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

Surprising use of template string value

After following a tutorial, I decided to create ProductScreen.js and Product.js. However, when implementing my code, I encountered some warnings. Can anyone help me identify the issue? product.js import React from 'react' import Rating from &apo ...

Update data in PHP dynamically without reloading the page

It would be great if they are doing well! I have encountered a minor issue - everything seems to work perfectly, but it doesn't quite meet my requirements. I am referring to this particular function: <script> var previous = null; var current = ...

Filtering data from a list of objects in Angular when clicked

0: {user_id: 1, status: Active, account_request_status: 2, first_name: null, last_name: null, email: null,…} 1: {user_id: 3, status: Inactive, account_request_status: 0, first_name: null, last_name: null, email: null,…} 2: {user_id: 37, status: Rejecte ...

Trigger a function following a collection update in Angular Meteor

I am in the process of developing a multiplayer game, and I would like a specific function to be triggered once the first player updates an "isStarted" field in the collection. Within my controller code: angular.module('mcitygame').directive(&a ...

How can I establish the conversion from pixels to em units?

According to a source I found, 1 em is equivalent to 16px. You can read more about it here. Despite setting the font-size to 100% in the body and using font-size: 1em, the standard font size in my Jekyll site remains 12px. Curious? Visit my Jekyll site a ...

Receiving an empty string from Chrome FileReader when dealing with large files (300MB or more)

Objective: The task is to read a file from the user's file system as a base64 string in the browser The size of these files can be up to 1.5GB Challenge: A script that works flawlessly on Firefox, regardless of the file size On Chrome, the script p ...

Having issues with my jQuery getJSON request. It's returning an empty response even though

I have been struggling to find a solution to this particular issue with no luck... Here is the jQuery getJSON request that I am working on: $.getJSON("http://localhost:8080/context/json/removeEntity.html", { contentId : 1, entIndex : entityIndex ...

A method that sorts an array of objects based on their properties

I am currently working with two specific objects: clinics: [ { id: 1, name: 'New Hampshire Veterinarian Clinic', plans: [ 'handle123', 'handle567', ] }, { ...

A step-by-step guide on how to use the Google Closure Compiler: a

Is there anyone who could assist me in adding a snippet to the basic process of Google Closure Compiler? I have been trying unsuccessfully to do this via JavaScript code. I am using an example snippet from the official npm page, but when I run it, someth ...

Issue with Firefox not entering FullScreen when using the userChrome.css file

1) Below is a screenshot of my customized Firefox interface. After tweaking my userchrome.css file to remove tabs, I noticed a large empty space at the bottom of the browser window that I cannot seem to get rid of. Despite trying various solutions, I have ...

Steps for logging in using Spring Boot and Angular 2

My Front End application is built with Angular 2 and runs on http:// localhost:5555. Meanwhile, my Back End application uses Spring Boot and runs on http://localhost:8080/. It provides a REST API for my Angular 2 application. Sending requests from http:/ ...

The message of error is undetermined

Can someone help me with using the errorMessage object from routes in a partial? I have attempted to implement it as shown below: Route:- const express = require("express"); const router = express.Router(); const Character = require("../models/character" ...

Filtering relations in TypeORM can be achieved by using various query criteria

Hello, I have a couple of questions regarding TypeORM in TypeScript. Using Find() Only: I have two tables in my database - Users and Sessions. I am interested in retrieving a specific User along with all their Sessions where the sessions_deleted_at column ...

Unraveling Complex Observables with RxJS

I am facing a challenge with Rxjs that I need help solving. The data returned from the API looks like this: [ { name : test1, code : [1, 2] }, { name : test2, code : [1, 2, 3] }, ... ] What I want to achieve using Rxjs is to t ...

Gather data from various HTML elements with JavaScript when submitting a form

How can I extract values from HTML elements and send them for processing through a form? I'm attempting to compile a menu item list with the individual items' structure in place, but I'm struggling to figure out how to fetch the values upon ...

encountering a problem with permissions while attempting to update npm

Has anyone encountered a permission error with npm when trying to update to the latest version? I recently tried updating npm and received this error message. I'm unsure of how to resolve it. Any suggestions? marshalls-MacBook-Air:Desktop marshall$ n ...

Ways to retrieve my PHP output and display it on a page using Ajax

I'm struggling to combine the functionalities of a PHP script and Ajax on my website. I want to update content without reloading the page but facing issues. Although I can send input data through Ajax, I'm unable to retrieve the results effectiv ...

Errors in socket.on Listeners Result in Inaccurate Progress and Index Matching for Multiple Video Uploads

Is there a way to make sure that the `socket.on('upload-progress')` listener accurately updates the upload progress for each video as multiple videos are uploaded simultaneously? Currently, it appears that the listener is updating the progress fo ...

Images Are Failing to Load on the Webpage

I'm facing an issue with appending pictures of restaurants to dynamic div IDs. When I make the div ID static, the pictures show up fine from the server, but when I try to make it dynamic, the images don't get appended. Can someone please assist m ...

PHP Ajax not updating variable as expected

Apologies for the repetitive questions, but I have tried numerous solutions and cannot seem to figure out why this particular one is not working. I am invoking ajax through a click function, but I am unable to retrieve the jList value and update the variab ...