Can Angular 1.* ng-repeat function with Set
and Map
new objects?
Is there a roadmap to implement this integration?
Can Angular 1.* ng-repeat function with Set
and Map
new objects?
Is there a roadmap to implement this integration?
Angular utilizes the for..in
operator internally to loop through non-array objects. Check out the source link for proof. However, collections like Map
and Set
require the use of for..of
for iteration. Therefore, these collections cannot be used directly with ng-repeat
without additional conversions.
The upcoming Angular 2 will support ES6 features and will also include the for..of syntax for looping. Refer to angular 2 docs for more information.
I attempted to connect a Map
to ng-repeat
in Angular 2, but even with *ngFor="let item of items"
it was not successful. I found a solution that worked for me:
/*
* An extension of the ES6 map that also allows binding to its array of values
*/
class BindableMap extends Map {
constructor(...args) {
super(...args);
this.bindableValues = [];
}
updateBindableValues() {
// Clear the array without creating a new one.
this.bindableValues.length = 0;
// Add all the new values
this.bindableValues.push(...Array.from(super.values()));
}
clear(...args) {
super.clear(...args);
this.updateBindableValues();
}
set(...args) {
super.set(...args);
this.updateBindableValues();
}
delete(...args) {
super.delete(...args);
this.updateBindableValues();
}
}
This allows you to use it in Angular 1.x as well with
ng-repeat="value in map.bindableValues"
.
It's worth noting that this may not be the most efficient solution, as the bindable values are recreated on every map change. However, it suited my needs. Additionally, you can expand the BindableMap
to bind to keys or key-value pairs if desired.
I'm currently exploring NextJS with SSR and encountering an error when trying to fetch data from a Spotify playlist using the spotify-web-api-js library. This issue only occurs when executing on the server side: error - ReferenceError: XMLHttpRequest ...
Having a blade with the following code snippet. <meta name="csrf-token" content="{{ csrf_token() }}"> <covid-form> </covid-form> Inside the covid-form component, there is a form structure like this: <form @submit.prevent="send"&g ...
Setting table headers: <th class='header'> <a href="" ng-click="orderByField='success'; reverseSort = !reverseSort"> Successes <span ng-show="orderByField == 'success'"><span ng-show="!reverseSort ...
I'm exploring the concept of JavaScript scopes and am curious about a specific scenario: // B has access to 'context' var x = function (context) { y = function () { console.log(context); }; y(); }; x('cool'); ...
I have encountered a perplexing issue when attempting to import an API module into a nested component within a Vue application. After simplifying the problem as much as possible, I created a codesandbox example to demonstrate it. The problem arises when ...
Having an issue with direct links to pages containing a parameter. While links from the page itself work, accessing the page directly or refreshing it causes it to break and not load anything. This problem is occurring within a blog application I am develo ...
Is it possible to iterate through specific elements in ng-content and assign a different CSS class to each element? Currently, I am passing a parameter to enumerate child elements, but I would like to achieve this without using numbers. Here is an example ...
There are numerous techniques available to share data between controllers in Angular, such as accessing prototypical data from a parent scope, utilizing scope events for controller communication, or implementing shared services. However, what is considere ...
As I attempt to enhance the testability of my NodeJS API by incorporating a service, a peculiar issue arises. Specifically, upon injecting the service (class), an error is triggered stating that the method getTasks() does not exist. ROUTE const TodoServi ...
I am facing an issue with the JunitXML reporter as it is not generating the xml file. I execute the test using 'protractor example-test.js' command, but even though there are no errors, the file is not being generated. Can someone please assis ...
UPDATE It seems that my initial approach was completely off base. According to the accepted answer, a good starting point is the TodoMVC app built with React + Flux and available on GitHub. I am currently working on a small React + Flux application for ed ...
When using Bootstrap 3 "form-inline" within a <div>, I noticed that the div seems to be nested within the form-inline. This is how my code looks: HTML <div class="wrapper"> <div class="form-inline"> <div ...
Utilizing Google geocoding in my coding tasks has presented a challenge. I have around 50 places to geocode, but Google restricts the number of places that can be geocoded simultaneously, resulting in an 'OVER_QUERY_LIMIT' error. To address this ...
I am currently encountering an issue with tracking click position over a cross-domain iframe. Here is my current code: <div class="poin"> <iframe width="640" height="360" src="http://cross_domain" frameborder="0" allowfullscreen id="video">< ...
I am trying to create a script that will display a greeting message to the user based on their local time. I found a script on Stack Overflow, but I am struggling with updating the image source. When I try to replace the image source, I encounter the follo ...
I am experimenting with if statements, but I'm encountering some difficulties. My goal is to assign random numbers to a variable and then trigger different actions based on a click event. Here's what I've tried so far, but it seems to be fa ...
I am currently working on converting the LZW decompressor from PHP to JavaScript and I have encountered a function that is giving me some trouble. function decompressLZW(aCodes) { var sData = ''; var oDictionary = []; for (var i = 0; i &l ...
I am trying to generate a table dynamically using CSS and a JSON array. For example: In the code snippet provided, I have assigned a class of 'spannedrow' to span certain cells in the table, although the class is not defined yet. This is just ...
Hello, I have been searching for a solution to my current issue without much success. The problem revolves around retrieving dates from Firebase and populating them into UI elements in my Vue app. My end goal is to align each date with the corresponding mo ...
I am encountering a 404 status code error when trying to access app.get('/playlists'). The browser displays "cannot GET /playlists" and I can't seem to figure out why. Here is the code I am using: var express = require('express&apos ...