The peity function in Angular JS seems to be malfunctioning when used in conjunction with

When it comes to creating a basic pie chart, I like to use piety. It's simple to work with and functions well with JavaScript.

Here is an example in HTML:

<span class='pie' data-peity='{ "fill": ["#1ab394", "#d7d7d7", "#ffffff"]}'>0.52/1.561</span>

To make it work with JavaScript, you just need to add:

$(".pie").peity("pie");

Everything works great until you try using it within an AngularJS ng-repeat loop:

<div ng-repeat='item in data'>
     <span class='pie' data-peity='{ "fill": ["#1ab394", "#d7d7d7", "#ffffff"]}'>{{item.start}}/{{item.end}}</span>
</div>

Unfortunately, that doesn't seem to be working as expected.

I thought maybe I needed a directive, so I created one:

app.directive('pieChart', function ($timeout) {
return {
    restrict: 'A',
    link: function (scope, element) {
        $timeout(function () {
            element.peity("pie")
        }, 100);
    }
};
});

In the HTML, I then used:

<td><span data-peity='{ "fill": ["#1ab394", "#d7d7d7", "#ffffff"]}' pieChart>0.52/1.561</span></td>
without ng-repeat

However, even with the directive, it still doesn't seem to be working for me. I'm not sure why. Can anybody offer some assistance?

Answer №1

When creating a directive, remember to use lower camel-case for the name like pieChart. However, when using it as an attribute, make sure to switch to kebab-case, such as pie-chart

AngularJS normalizes tag and attribute names of elements to match with directives. Directives are usually referred to by their case-sensitive camelCase normalized name (e.g., ngModel). But because HTML is case-insensitive, directives in the DOM are referenced in lowercase forms, often with dash-delimited attributes (e.g., ng-model).

Check out the documentation here

View Naren Murali's JSFiddle example

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

AngularJS: Keep sending $http.get requests until a specified condition is met

Looking to continuously send $http.get requests to the server until a specific condition is met, as mentioned in the title. This was my attempt: var searchCompleted = false; var requestSent = true; while(!searchCompleted) // #2 and then jump ...

The measurement of a table cell's height containing hidden overflow child elements

I am looking to determine the actual height of the content within a table cell that has nested child items with overflow:hidden styles. Here is an example of the structure: <tr> <td id="targetid"> <div id="innertargetdiv"> ...

combine the values from various keys into one cohesive array

Here is an array of objects that I need to manipulate: [ { "name": "product1", "Jan": 3, "Feb": 2, "Mar": 0, "Apr": 1, "May": 3, "Jun": 0, "Jul": 0, "Aug": 0, "Sep": 5, "Oct": 0, "Nov": 0, "Dec": 0 } ...

Combining Objects in Three.js: Merge All Objects into a Single Entity

I am new to the world of three.js and recently I tried my hand at creating a custom shape using multiple objects. However, I encountered an issue where everything seemed fine when I added each object individually to the scene. https://i.sstatic.net/MWLYS. ...

Issues with Google charts loading may arise on ajax calls

Recently, I have been experimenting with incorporating Google Charts into my website to showcase data from Google Analytics. To enhance user experience, I decided to split my analytics reports into distinct sections such as Pages, Browsers, Operating Syst ...

Trying to modify a read-only property in React Native, got the error message "Attempted to assign to

Reflecting on My Journey(feel free to skip ahead) Recently, I delved into the world of mobile development with react-native, and let me tell you, it was a rollercoaster. After spending hours troubleshooting why my react-native init project wouldn't e ...

The ng-change functionality of Angular radio buttons only functions correctly the first time it

I am struggling to comprehend why the angular ng-change function is only being called on the first click. Take a look at this example: http://jsfiddle.net/ZPcSe/5/ The function in the provided example is triggered every time the radio selection is change ...

Can a file be loaded using JS/HTML5 FileReader on a page that is not being served?

I am looking to create a simple game using HTML5/JS without requiring the user to run a webserver or connect to a website. I only want them to access an HTML page. However, it seems like FileReader can only be used with file type inputs. Is there a way f ...

Learn how to display every ASCII or EBCDIC character once radio buttons have been selected

I'm currently working on a simple website that requires the user to input a minimum of 256 characters, choose between ASCII or EBCDIC for conversion, and then click the submit button (Run) to display the final converted result on the page. However, I& ...

Having trouble making alerts or confirmation dialogs function in JavaScript

EDIT: Many thanks to everyone who helped fix this issue (: Your help is greatly appreciated! I've been struggling to get the alert, confirm, or prompt functions to work properly in my code. Here's a snippet of the code that's causing troubl ...

Preserving the top line or heading while cutting through a table

In my HTML, I have a table with the following structure: <table id="table"> <tr> <td>ID</td> <td>Place</td> <td>Population</td> </t ...

Get the report from jsreport and angularjs now

Is there a way I can enable users to download a report from my AngularJS Application? The report format is in .xlsx. I am able to send the data, but the response received appears like this: https://i.stack.imgur.com/3OPra.png What I want is to provide a ...

How to style the currently active route link in Angular 2 using CSS

I want to add custom CSS styles to active router links: <a [routerLink]='link'>{{name}}</a> Here's what I attempted so far (Using the default router-link-active class): .router-link-active { color: #000; font-weight: bold; ...

Exploring the applications of the `this` keyword within a jQuery-based JavaScript object

Recently, there has been a challenge in creating a JavaScript object with the specific structure outlined below: function colorDiv(div){ this.div=div; this.div.bind("click",this.changeColor) this.changeColor(){ this.div.css(" ...

Troubleshooting performance problems in AngularJS when using Fastclick

While trying to enhance the performance of my ng application, I have encountered a peculiar side effect caused by FastClick. This has resulted in multiple dispatch Events (as shown in the attached image) and unnecessary $digest calls that I would like to ...

Is it possible to verify whether a Node Js query is empty or not?

I've been attempting to determine if a result query is empty or not, conducting thorough research in the process. Below is the code illustrating the query I'm executing and the two methods I employed to check if it's empty. The issue at han ...

Improprove the Express Router in a Node.js application

Is there a way to avoid repeating the isUserAuth and isAdminAuth middleware on each endpoint? Can I apply them just once so they work for all routes without having to specify them individually? const { createBranch, getAllBranch, getBranch } = require(&apo ...

Countdown timer options for Ionic and Angular 2

I am in need of a simple Angular 2 (4) / Ionic 2 Countdown timer for my project, but unfortunately I haven't been able to come across any open-source options. That's why I'm turning to you all for suggestions. Here is an example of what I h ...

Executing a command in the terminal does not yield the identical outcome as executing it from the debug feature

Below is the code that I am currently working with: var Tesseract = require('tesseract.js') var filename = '2.jpg' Tesseract.recognize(filename) .progress(function (p) { console.log('progress', p) }) .c ...

A guide on transferring and transforming text data on the server

While I have a basic understanding of php, ajax, and javascript (including jQuery), I am still a beginner and could use some assistance with connecting the dots for this simple task: My goal is to allow the user to input text (for example: "I saw the sun, ...