Angular: Enhancing View Attribute by Eliminating Extra Spaces

I'm using an ng repeat directive to dynamically set the height in my code.

 <ul>
<li ng-repeat="val in values" height-dir >{{val.a}}</li>
</ul>

    app.directive('heightDir',function(){
return {
    restrict: 'AE',
    replace: true,
    template: '<li ng-repeat="val in values" style="height:{{val.b}}%" >{{val.a}}</li>',
    link: function(scope, elem, attrs) {

    }
  };
});
$scope.values= [{a:"Doe",b:10},{a:"bom",b:20},{a:"kal",b:30},{a:"jijo",b:40}];

Upon running the code, I noticed a gap between the value and % where the style was not applied. Can anyone suggest a solution to this issue? Any help is appreciated. Thank you.

Answer №1

It appears that there may be an issue with the HTML markup being incorrectly generated.

Check out the code snippet below:

<div ng-controller="MyCtrl">
    <ul style="height:500px">
        <height-dir ng-repeat="val in values"></height-dir>
    </ul>
</div>

Here is the corresponding JavaScript code:

var myApp = angular.module('myApp',[]);

myApp.directive('heightDir',function(){
    return {
        restrict: 'AE',
        replace: true,
        template: '<li style="height:{{val.b}}%" >{{val.a}}</li>',
        link: function(scope, elem, attrs) {
    }
  };
});

function MyCtrl($scope) {
    $scope.values= [{a:"Doe",b:10},{a:"bom",b:20},{a:"kal",b:30},{a:"jijo",b:40}];
}

For a live demonstration, visit the following Fiddle link: http://jsfiddle.net/HB7LU/12044/

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

I am eager to retrieve intricate JSON data with the help of AngularJS

Hey there, I'm currently struggling to implement a third level select option and can't seem to retrieve data from JSON. Could someone please assist me or point out where I might be going wrong? var app = angular.module('myApp', []); ...

Having trouble understanding how to display an HTML file using Next.JS?

Currently, I am working on a project that involves utilizing Next.JS to develop a webpage. The main goal is to display a PDF file on the left side of the screen while integrating Chaindesk on the right side to create a chat bot capable of extracting inform ...

In React + TypeScript, learn how to effectively pass down a function from a container component to a

I am currently working on developing a tabs application using React and Typescript. The main component, Tabs, manages the state and passes it down to the Content component. Additionally, I have implemented a function called 'handleName' which is ...

What could be the reason for v-model not functioning properly?

Embarking on my Vue.js coding journey, I am currently following a straightforward online tutorial. Utilizing the vue-cli, I kickstarted my application and crafted a basic component named Test.vue. Within this component lies a simplistic input control conne ...

Tips for showcasing the error message from the back-end instead of the status code

After setting up a Backend server and deploying it to Heroku, I have been using the server URL to send and receive data. However, I've encountered an issue where instead of displaying the actual error message, the status code is being returned. Here ...

Encountered an error while using JSON.parse(): `SyntaxError: Unexpected token in JSON at position 0`

As I embark on my Node.js development journey, I am faced with a challenge while trying to retrieve data from a JSON file. An error message interrupts my progress: SyntaxError: Unexpected token  in JSON at position 0 at Object.parse (native) Below is ...

The error message "Cannot read property 'addEventListener' of undefined" occurred while trying to register the service worker using `navigator.serviceWorker.register('worker.js')`

I'm grappling with a JavaScript issue and need some help. You can find the demo of the functioning script by the author right here. I've implemented the same code as displayed on his demo page. I've downloaded the worker.js file and ...

Tips for recognizing a specific object ID within an array in order to modify the status of an element within that object

My goal is to accurately identify a specific panel within an expanded array and link that panel's ID to a button, while also ensuring the button is disabled when no panels are expanded or more than one panel is expanded. However, I am encountering iss ...

Advantages of placing script src tags at the top of the body versus placing them at the bottom of the body

I've heard that it's best to place the script tags right before the closing body tag. However, when I follow this advice, my angularJS expressions don't seem to compute correctly for some reason. When I place the script tags in that location ...

Transmit information to Angular application upon being delivered by Express

I am currently working on an Angular application powered by Express 4.0. I am looking to send data to the front end during startup, specifically when the index file is being served. However, I am struggling to determine the most appropriate route to accomp ...

I could really use some assistance with the concept of "AJAX" - can anyone help

After spending several months working with AJAX, I have come to understand the typical request lifecycle: Sending parameters to a background page (PHP/ASP/HTML/TXT/XML ... what other options are available?) Performing server-side processing Receiv ...

Revamping JSON structure by identifying id references

I recently attempted to update the city name within the JSON object provided below. "City":[ { "Name":"Delhi", "id":"c5d58bef-f1c2-4b7c-a6d7-f64df12321bd", "Towns":[ ...

Just released a new npm package called vue-izitheme. It's fully functional from the command line, but for some reason it's not showing up in search results. Any suggestions on how to fix

I released my project, vue-izitheme, two days ago but I can't seem to find it when searching. It is functioning correctly from the command line and has already been downloaded 44 times. Do you have any thoughts on what could be causing this issue? ...

having difficulty inputting time into a time controller with selenium webdriver

This is the HTML Code: <mat-form-field _ngcontent-c18="" class="mat-input-container mat-form-field ng-tns-c7-23 mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float mat-primary ng-untouched ng-pristine ng-invalid"><d ...

Passing a JavaScript value to a Bootstrap modal and then utilizing it as a C# variable

I’ve been grappling with this issue for the past few days, and it seems like I might be overthinking things. When I open a bs modal dialog, I can successfully pass a value via the data-id attribute. I can also store this value in a hidden field or div. ...

Adjust the map automatically as the cursor approaches the map's edge in Google Maps API V3

My latest project involved creating a selection tool using the Rectangle shape tool. With this tool, users can easily select markers by drawing a rectangle over them and releasing their mouse to erase the selection (similar to selecting items on a desktop ...

Modifying the state object in ReactJS: A step-by-step guide on updating values

Below my query and explanation, you will find all the code. I am currently attempting to update the state in a grandparent class. This is necessary due to file-related reasons, and I am using Material-UI for text boxes. Additionally, I am implementing Red ...

What is the best way to dynamically change the main content based on the sidebar option chosen in a React application?

https://i.sstatic.net/fkIyh.png Currently, I am in the process of creating the layout for the page similar to the image provided. When a user selects option A from the sidebar, my goal is to display the corresponding content on the same page without navig ...

Encountering Rendering Issues with EJS Post HTML Conversion

After working on a much larger project for over a month, I'm now six hours into troubleshooting and everything is starting to blend together. Prior to switching to EJS, everything was working perfectly. I'm not looking for someone to solve the ...

The getelementbyid function is unable to locate the specified button identifier

As I dive into the world of Javascript, I wanted to create a simple input form with a corresponding response field on my website. However, I encountered an issue where using a basic submit button caused the page to refresh and erase the textfields before ...