Achieving consistent height for child divs in AngularJS when one div's size is changed dynamically using ng-repeat

For my project, I have set up a parent div with two child divs inside. The first child div contains a list generated using ng-repeat and has a border around it. This div's height adjusts based on the list items. Now, I need the second child div to match the height of the first one so that both borders align perfectly within the parent container. While I know how to achieve this using jQuery, I'm interested in exploring simpler solutions using CSS or AngularJS. Any guidance on this would be greatly appreciated.

Here is an example demonstrating the issue on Plunker: http://plnkr.co/edit/yGI1cJ3y594O89bEZAIH?p=info

<script data-require="angular.js@*" data-semver="1.4.0-beta.4" src="https://code.angularjs.org/1.4.0-beta.4/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>

Issue: Equal Height for Child Divs

<div class="row" ng-controller="mainCtrl">
  <div class="col-md-6" style="background-color:lightblue; border-style: solid; border-width:1px;">
    <div class="col-md-12" ng-repeat="item in items" >
      <div>{{item}}</div>
    </div>
  </div>
  <div class="col-md-6" style="background-color:lightred;border-style: solid; border-width:1px;">
    <br />
    Enter new item to see in the list:
    <br />
    <input type="text" ng-model="newItem" /> 
    <input type="button" ng-click="addItem()" value="Add" />
  </div>
</div>


<script>
var app = angular.module("mainApp", []);
app.controller("mainCtrl", function ($scope) {
  $scope.items = [1, 2, 3, 4, 5, 6, ];
  $scope.newItem = "";

  $scope.addItem = function() {
    $scope.items.push($scope.newItem);
    $scope.newItem = "";
  }
});

</script>

Answer №1

It appears that this question may be a duplicate of another question which I have addressed previously, you can find the original question here.

A possible solution involves creating a Directive in AngularJS that monitors height changes within a div element:

app.directive('master',function () {
    function link(scope, element, attrs) {
      scope.$watch(function(){
        scope.style = {
            height:element[0].offsetHeight+'px',
            width:element[0].offsetWidth+'px' 
          };
      });
    }
      return {
        restrict: 'AE',
        link: link
      };
});

For more detailed information, please refer to my previous answer linked above.

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

The div content is being forced downward

I recently implemented a two column layout on my WordPress site, and to ensure it remains responsive when the browser width is reduced, I utilized this specific solution. While the solution generally works well, I encountered an issue where the content in ...

Showcase pictures from a directory in real-time using a combination of jQuery and Bootstrap as the folder continues to fill up with images

Although I am just beginning to learn about UI, I have a question that seems important to me. In my application, there is a background thread that downloads images and saves them in a folder named "images". I want these images to be displayed in the UI as ...

Upon script load, a random item from an array will be displayed and recorded in a separate array

I'm working on a fun code project where I aim to display random animal names in different colors that change when a specific keyboard key is pressed. The challenge I'm facing is that the first random animal name in a random color only appears aft ...

Developing alternatives for CSS Grid

Currently, I am faced with an intriguing challenge involving a layout that includes a container containing 9 div elements. Each of these divs is assigned one of three classes: column-1, column-2, or column-3. <div class="grid cols-3"> <div cl ...

Tips on modifying classes within specific sections of HTML tables

I attempted to create calendar-like tables, In my script, I am trying to handle events being registered. My goal is to change the classes of cells from 2 to 5 when they are clicked on, and change the cell colors from first to hovered to aqua. For this p ...

The functionality of Jquery radio:checked is not behaving as desired

Currently, I am in the process of learning jquery. I have created a basic html file with some jquery validations, however, they are not functioning as expected. The main problem is: If I input my name first and then check the checkbox, everything works co ...

How to Extract Information from a Table Enclosed in a Div Using HTML Parsing?

I'm new to HTML parsing and scraping, looking for some guidance. I want to specify the URL of a page (http://www.epgpweb.com/guild/us/Caelestrasz/Crimson/) to grab data from. Specifically, I'm interested in extracting the table with class=listing ...

Gradually introduce each element in sequence

I've written some code that works, but it's a bit messy with all the repeated lines. I tried using a loop to clean it up by replacing [0] with [i], however, the elements end up fading in simultaneously. Here is an example of my code on JSFIDDLE. ...

Issues with Font-Face Implementation

Hey there! I'm currently working on incorporating a new font into my website using font-face. However, it seems like something might be missing from my code because the style isn't being applied correctly. Here is what I have so far: <div id= ...

What is the best way to create a responsive design that positions an element between two others?

There are two types of elements in my project: Type "A" - a text block Type "B" - a graphical block I am looking to create a responsive layout for these elements. On small resolution screens, I want them to be arranged like this: "A" "A" "B" ...

Struggling to keep my image buttons aligned in a horizontal line at the center, but they keep stacking vertically instead

I'm struggling to keep a row of image buttons centered horizontally, regardless of the window size. However, when I manage to center the buttons, they end up stacking vertically instead of aligning in a single line. I've experimented with differ ...

Having trouble clicking on SubMenu with selenium web driver

Currently, I am looking into automating a UI application. In this application, there is a menu that displays sub-menus upon hovering the mouse over it. However, I am facing an issue where I am unable to click on the items within the sub-menu. Here is the ...

What is the process for generating a printout of an element's value?

For the purpose of debugging, I am trying to print the text value of an element to the console. Here is what I have: var result = element(by.model('vm.firstName')).getAttribute('value'); console.log('The first name is: ' + re ...

Adding two BR tags between inline images within a wrapper is causing inconsistencies in spacing when viewed in Firefox compared to all other browsers. Check out an example of this issue in

JS Fiddle Link http://jsfiddle.net/Xfvpu/1/ Having a perplexing issue with image rendering in Firefox compared to other browsers. The xhtml doctype is used with proper br / tag spacing, but the gap between two images on this specific document displays dif ...

Dispatching identification to controller after submission

I am encountering an issue with a page that contains the following code: <div class="col-sm-2 displaybutton"> <div data-point-to="displaysHeader"> @using (Html.BeginForm("Administration", "Home", FormMethod.Post)) ...

Mark the term on the backspace key and remove it after pressing the second backspace button

<html> <body> <div id="textareaId" contenteditable="true"> Hello there </div> <button onclick=selectText(0,4)>Click to select</button> <button onclick=deleteSelectedText()& ...

NativeScript GridLayout not rendering as expected

Issue with NativeScript Screen Layout I have been attempting to design a screen in NativeScript, but I am encountering some complications. Initially, I aimed to replicate the following screen: https://i.sstatic.net/tfa7w.png Despite following the recomm ...

Discover the interactive world of HTML5 Canvas on iPhone with exciting highlights triggered by touchstart or mousedown

The canvas changes to a darker color when touched and held, reverting back to normal when the touch is released. This effect is similar to how hyperlinks are highlighted on an iPhone, not like text selection. To implement this feature, I am using jQuery t ...

Understanding the response format in jQuery and AJAX

Can anyone advise on the optimal data format for communication with JavaScript? Should I stick to JSON or use plain HTML instead? Are there any alternatives worth considering? ...

alter the input information using AngularJS

Every time I try to edit the entry, it takes me back to the form. However, once I hit enter, the null values are saved and I'm not sure why this is happening. I suspect that the issue lies in not pushing the entire object (including name, title, and ...