Varying gaps between individual directives and identical directives within ngRepeat

The issue at hand: There appears to be a major gap between simple directives and the same directives used in ngRepeat, especially when using display: inline-block in the Chrome browser.

Check out the Plunker here

  1. I can add an unlimited number of directives and everything works fine:
<tile></tile>
<tile></tile>
<tile></tile>
<tile></tile>
  1. However, if I include something like ngRepeat, the layout breaks:
<tile></tile>
<tile></tile>
<tile></tile>
<!-- There is suddenly a large gap here -->
<tile ng-repeat="t in [0, 1, 2, 3]"></tile>

Here is the code for the directive:

 .directive('tile', function () {
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            template: '<div class="tile"></div>',
            controller: function ($scope) {},
            link: function (scope) {}
        };
    })

The CSS class for the directive .tile:

.tile {
  background-color: red;
  height: 70px;
  width: 70px;
  margin: 4px 2px;
  display: inline-block;
}

So, why is this happening? What could be causing it, and how can it be resolved?

Answer №1

To eliminate the gaps between tags, we need to ensure that the elements are displayed as inline-block so that whitespace does not affect their positioning.

Answer №2

To incorporate float: left; into your CSS, refer to the demonstration provided below:

angular.module('app', [])

.directive('tile', function() {

  return {
    restrict: 'E',
    scope: {},
    replace: true,
    template: '<div class="tile"></div> ',
    controller: function($scope) {

    },
    link: function(scope) {


    }
  };
});
.tile {
  background-color: red;
  height: 70px;
  width: 70px;
  margin: 4px 2px;
  display: inline-block;
  float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app='app'>

  <div class="wrap">

    <tile></tile>
    <tile></tile>
    <tile ng-repeat="t in [0, 1, 2, 3]"></tile>

  </div>
</body>

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

What might be causing the image links to malfunction on the server while functioning normally when offline?

Recently, I've been working on a website and after successfully testing it offline, I decided to put it online. However, I've run into an issue where some images are not showing up. What's even stranger is that the images that are appearing ...

Can you explain the meaning of EPS in the THREE.OrbitControl function?

The this.update method within the THREE.OrbitControl script contains a private variable called EPS, which is used to adjust the phi angle. The following code snippet demonstrates how it restricts phi to be between EPS and PI-EPS: // restrict phi to be bet ...

I'm having trouble aligning two divs side by side

Does anyone have any suggestions on how to align <head> and <head> horizontally? I've attempted using the CSS code below, but it doesn't seem to be working: .header_nav { float:left; clear:both; } You can view the actual pa ...

Guide to interpreting an Angular expression using traditional JavaScript conventions

I have encountered an issue with the Angular app that I am currently working on. It needs to retrieve the Google Analytics ID from Angular in order to pass it to ga('create', 'UA-XXXXX-Y') using standard JavaScript in my index.html. &l ...

PlateJS: Transforming HTML into data

Trying to implement a functionality where clicking on a button retrieves an HTML string. The objective is to have this rich text editor within React-Hook-Form, and upon form submission, the value will be saved as HTML for database storage. Below is the pr ...

Why is my HTML element showing up as text in Angular-strap?

I recently installed angular-strap and I am experimenting with some of its features. Although I have a modal working, the <br /> element is not being rendered correctly as it appears as text instead. Despite checking the documentation which indicates ...

Socket.io allows us to broadcast messages to all users connected to the server using the "io

I've set up a MEAN app using npm socket.io with expressjs and btford.socket-io on the client side. angular.module('myApp',['btford.socket-io']) .factory('socket',function(socketFactory){ return socketFactory() ...

Searching for the way to access the values of a nested object's ref in Vue JS?

Within my Vue data object, I store a reference to a structure called Plot. It has properties for length, width, and acreage. interface Plot { length: number, width: number, acreage: number } const model = { plot: ref<Plot[]>([]), }) When fe ...

Using Scrapy and Selenium to interact with dynamic elements on a webpage

When I crawl the page, I come across an element that looks like this. <a class="a-declarative" href="javascript:void(0)" data-action="a-expander-toggle" data-a-expander-toggle='{"allowLinkDefault":true, "expand_prompt":"See more", "collapse_pro ...

Is there any way to prevent these faces from being displayed?

Recently, I've been working on a cube-based game using three.js and encountered an issue with rendering transparency in blocks. These blocks are loaded from a JSON file, where each block is defined like this: { 'sprite': 'water.pn ...

Display thumbnail images in jquery-ui dropdown menu

Hello, I'm looking to display a small image (the user's thumbnail) on the jquery-ui dropdown by making an ajax call. As someone new to ajax and unfamiliar with jquery-ui, I would appreciate some guidance in the right direction. Thank you! HTML/J ...

What could be causing my nested child component to fail to display the content?

My current setup includes: Vue 2.5.16 Veux Vue router I have created a simple router view that searches for a child component within a parent component using the URL structure: /folders/parent-uuid/child-uuid Below is the code for the parent component ...

Is the format of the ISOString valid?

How can I verify if a field is in ISOString format? It works fine when I input a valid date such as const create = '2018-08-02T02:07:49.214Z', but it causes an error in the script when I use const create = 'b'; Here is an example: ...

"Exploring the power of AngularJS: Combining server side validation with dynamic client

Currently, I am trying to grasp the concept of declaring a form properly. My understanding is that one should simply declare the form in HTML and include ng-model directives like this: ng-model="item.name" When it comes to sending data to the server, I b ...

Angular 7: Finding the variance between array elements

How can I subtract the values from the first 3 rows of the table? The formula is TVA Collectée - TVA Déductible - TVA Déductible/immo If the result is positive, it should be displayed in the box labeled TVA à Payer. If it's negative, it should g ...

Using Vue JS to create advanced select dropdowns

In the process of developing an application that relies on dropdown menus to assign input fields from a CSV file, I encountered a challenge. I wanted to incorporate logic that would automatically select certain options based on specific conditions. However ...

Using JavaScript to Filter JSON Objects

After making a php ajax call, I have received the following JSON data that needs to be displayed to the users: JSON {"headers":{},"body":"{\"comuni\":[{\"datapresub\":\"08\/08 ...

"Disabling options in HTML select element not supported in Microsoft Edge browser

I am facing an issue with the following code snippet: <div class="input-field col s12"> <select [(ngModel)]="view.frequency" > <option value="" disabled selected>Select frequency</option> <option [value]="1">Ne ...

Enabling visibility of overflowing text in dynamically inserted divs without using scroll bars

Is there a way to set the text overflow to visible without scroll bars in dynamically added <div>s? Despite what the documentation says, it doesn't seem to be the default behavior and I'm struggling to understand why. Adding text directly t ...

Unlocking the Potential of External Values in Angular Beyond http.then

Here is an example of my controller code: var app = angular.module('myApp'); app.controller('myCtrl', function() { $scope.year = "1350"; $scope.ord1 = ""; $scope.s1t1 = function() { $http({ url: 's1 ...