AngularJS alert with ng-show functionality

I am attempting to showcase specific alerts using AngularJS. You can reference the alert section at http://angular-ui.github.io/bootstrap/. My goal is to adjust the example so that only alerts with a "show" attribute set to true are displayed:

  $scope.alerts = [
    { type: 'error', msg: 'Oh snap! Change a few things up and try submitting again.', show: true }, 
    { type: 'success', msg: 'Well done! You successfully read this important alert message.', show: false }
  ];

I have included ng-show="alert.show" in the alert tag, but it appears that no alert is being shown. You can access the code here: http://plnkr.co/edit/Qbv4A9u1SnQeJy9o81lK?p=preview.

What mistake have I made? Thank you in advance!

Answer №1

Reorganize the placement of ng-repeat and ng-show within a parent div.

<div ng-controller="AlertDemoCtrl">
  <div ng-repeat="alert in alerts" ng-show="alert.show">
    <alert type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
  </div>
  <button class='btn' ng-click="addAlert()">Add Alert</button>
</div>

ng-show is an individual directive that may not be functioning properly when paired with the alert directive from UI Bootstrap.

Modified Plunker Link

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

Retrieve data from json files

After retrieving this object from my controller, I have a name, a list of beans, and a list of operations: { "name": "Charge", "beans": [ ], "operations": [ { "name": "getSize", "returnType": "java.lang.Integer", "descriptio ...

When using $scope.$eval(), performing calculations will reveal a result. Double-click on the result and enter a number, which unexpectedly adds "undefined" to the

This angular calculator is designed to perform simple calculations, but there are some issues with using eval(). When using $scope.$eval(), after performing a calculation, double clicking on the result and entering a number results in an undefined value b ...

Customizing a thumbnail script to dynamically resize and display images according to their size properties

I am attempting to modify a simple JavaScript script that enlarges an image from a thumbnail whenever it is clicked. The issue I am facing is that the enlarged image is displayed based on a fixed width size. I want the enlarged image to be displayed accord ...

Codeigniter code to retrieve dynamic data in a select box

I am trying to implement a functionality where selecting an option from one dropdown will dynamically populate the options in another dropdown based on the selection. I believe I need to use an onchange function, but I'm unsure how to retrieve data fr ...

How can I smoothly navigate to the top of a page using AngularJS?

After receiving an ajax call response using angularjs, I am looking to automatically scroll to the top of the page. The purpose is to bring focus to alert messages displayed at the top of the page upon receiving the ajax response. Appreciate any guidance ...

Importing WebAssembly dynamically can sometimes lead to complications with the order of execution

I am attempting to load a WASM library from another node js application, both utilizing webpack. Within the WASM library, I have the following code snippet exporting the functionality. export default import("./pkg") .then(s => { le ...

React Image Error Handling: How to deal with broken images in

I am currently working on a project where I need to retrieve the maxresdefault of various YouTube thumbnails. However, some YouTube videos do not have high-resolution thumbnail images available. To handle this scenario, I added an onError prop to the img ...

Encountered an issue with AngularJS + Firebase where the resource failed to load: The server with the provided hostname could not be located

I have been working on the 'Wire Up a Backend' tutorial from the AngularJS website and encountering errors that appear like this: [Error] Failed to load resource: A server with the specified hostname could not be found Seems like there' ...

Arranging icons at the bottom of the post with a text box that changes dynamically

My challenge is that when the content in a box overflows, the box size increases and pushes the icons out of place. I want to ensure that the icons remain in a fixed position. This is how it currently looks: The comment, delete, and likes count end up on ...

Guide: "Implementing a dynamic template reference in a function"

I have a function below that uses the setModelData method. My question is about making the template variable dynamic for both the getGlobalList and getNonGlobalList functions. For Example: 1) If getGlobalList is running, it will set template: this.Custo ...

Modifying URLs with backbone.js

When it comes to my Backbone module, I typically access it via the URL: http://localhost/src/index.html#test_module However, there is another module that I need to view which can be accessed using the URL: http://localhost/src/index.html#test_module ...

How do I switch the background-image on li hover and revert it back when I move off the li element?

Looking to update the background image of a div upon hovering over a li element? Check out this example here. So far, I've got that part working fine. But now I want the background picture to revert back to its original CSS when I move away from the l ...

I am looking to optimize my CSS and jQuery code for a dropdown menu

I have the following code that is currently functioning properly for a dropdown menu, but I need to make some modifications to the CSS and jQuery. I am looking to increase the size of the main box and decrease the width of the first row of icons. Howev ...

What is the best way to attach an EventListener to all DOM elements with a particular class?

Within my DOM, I have dynamically created spans that all have the class "foo". Utilizing TypeScript, I aim to attach an onClick event to each of these spans post-creation. Here is my current approach: var foos = document.body.querySelectorAll(".foo"); f ...

Unexpected disappearance of form control in reactive form when using a filter pipe

Here is a reactive form with an array of checkboxes used as a filter. An error occurs on page render. Cannot find control with path: 'accountsArray -> 555' The filter works well, but the error appears when removing any character from the fi ...

`Is there a way to modify the attribute text of a JSON in jQuery?`

I'm attempting to modify the property name / attribute name of my JSON object. I attempted it like this but nothing seems to change. After reviewing the input JSON, I need to convert it to look like the output JSON below. function adjustData(data){ ...

Pause the timer once it has reached a specific duration

My challenge involves utilizing a javascript timer that starts at 00:00 and needs to stop at 00:10 (10 seconds duration). The issue at hand is how to continuously monitor the current timer value to appropriately pause it after the designated 10 seconds ha ...

Develop a feature within a standard plugin that allows users to add, remove, or refresh content easily

I have developed a simple plugin that builds tables: ; (function ($, window, document, undefined) { // Define the plugin name and default options var pluginName = "tableBuilder", defaults = { }; // Plugin constructor func ...

A guide on implementing the grid feature in Angular.js

Looking to add the following features in my Angular grid: Paging Filtering Column-wise sorting Can anyone recommend an Angular JS grid that supports these functionalities? ...

Refresh database post drag and drop operation

I am seeking a way to update a "state" SQL row after dragging an element between the "DZ", "WT", and "ZK" divs. Below is a snippet of my code: SQL queries: $sql = "select * from tasks where login = '$user_check' AND state = 1"; $sqlDodane = mys ...