Utilize the $filter method within the controller to manipulate the ng-repeat array

Currently, I am attempting to apply a $filter to an array that is populating ng-repeat from the controller. This particular array defines the contents of "list" for ng-repeat="l in list".

Is there a way to achieve something like this?

var sidePanelFilter = $filter('sidePanel');

if (condition) {
    var numArray = myService.items;
    $scope.list = sidePanelFilter(numArray);
}

This is how my HTML looks:

<li ng-repeat="l in list | orderBy track by $index">
  {{ l }}
</li>

I am looking to set the $filter in the controller so that I can dynamically generate the list. It is important for me to keep the array's contents intact without making any changes.

Edit

I have created a codepen that showcases the issue I'm facing.

Answer №1

Based on your request, the objective is to modify the contents of the array instead of extracting a subset. In this case, utilizing a filter method would not be suitable; rather, you should utilize a method like array.map.

numArray = numArray.map(function(i) {
    return i + " meters";
});

http://codepen.io/anon/pen/hDGKjs

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 xhr.upload event listener is triggered when the xhr.responseText is empty after loading

const request = new XMLHttpRequest(); request.open('put', url, false); request.upload.addEventListener('load', function(e) { alert(request.responseText); }, false); Why is the responseText property of the XMLHttpRequest object empt ...

AngularJS makes it easy to push parameters to a URL in order to

I'm currently working on an AngularJS app where I need to dynamically push the user's company name to the URL. For example, it should look like www.myapp.com/samsung or www.myapp.com/toyota. My approach to achieve this is to first retrieve the u ...

What is the best way to filter out empty arrays when executing a multiple get request in MongoDB containing a mix of strings and numbers?

I am currently working on a solution that involves the following code: export const ProductsByFilter = async (req, res) => { const {a, b, c} = req.query let query = {} if (a) { query.a = a; } if (b) { query.b = b; } if (c) { ...

Preserve the newline character within a string in JavaScript

One of my API methods returns an RSA key in the following format: "publickey" : "-----BEGIN PUBLIC KEY-----\nMIGfMA0G CSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5WleAVeW5gySd QVFkTi44q1cE\ncWDT2gmcv2mHcWhwI/9YqGV2LqpMASe 4t4XS/88fvTTHafHn1KaL9F7d73T9k4cp&bs ...

SVG polyline animation that persists seamlessly

In my TypeScript code, I have implemented a function that creates a polyline based on 4 different points (x1y1, xCy1, xCy1, x2y2), where Xc represents the half distance between x1 and x2 on a plane. This polyline does not form a circular shape. private cre ...

Verify whether the input is currently being focused on

My current issue involves an input field that requires a minimum number of characters. If a user begins typing in the field but then switches to another without meeting the character requirement, I would like to change the text color to red. I attempted u ...

Navigating Unknown Properties in Angular: A Guide to Iterating Through Arrays

I'm having trouble coming up with a title for my question. I want to loop through an array of dynamic objects coming from a database, but I don't know the properties of the objects. Here's an example of the array object: [{ "id": 9, ...

Sorting the order of items for display through the Dropdown menu feature in Bootstrap

I'm working on an app that showcases recipes on the main page (mywebsite.com/recipes). I'd like to give users the option to sort the recipes by either date or popularity, with a button right on the page for easy selection. Currently, I'm usi ...

Puzzle involving unusual interactions with HTML, JS, and CSS scrollbars

I'm embarking on a special mission using CSS, HTML, and jQuery. My goal is to prevent scrolling when I hover over a specific element on the page. Right now, I'm accomplishing this by setting the body's overflow property to "hidden." However, ...

The NodeJS nedb function seems to be ignoring the await keyword

The time it takes for the function checkExists to run is too lengthy. Despite attempting to implement await and async functions, using var exists = await checkExists(data.email); still results in undefined value due to not properly awaiting for checkExists ...

Is there a formatting error when pulling data from an API using Angular?

The data retrieved from the API follows this format: { “array1”:[ {"id”:1, ”someProperty”:”A"}, {"id":2, "someProperty”:”B”} ], “array2”:[ {"id”:1, ”anotherProperty”:”foo”, ”lastProperty”:”foo2”}, ...

Angular is able to asynchronously make an API call and then effectively utilize the returned data

I am attempting to make an API call ngOnInit(){ this.function1() } function1(){ this.userService.getUser() .then((data) => { this.user = data.user this.userM = data.userM // I have a problem here: When I console.log(this.userM) it starts of ...

AngularJS orderby function organizes both numerical values and dates by treating them as strings

I am in need of creating a dynamic table using angular js to present data from a third party source that cannot be modified. The data to be displayed is completely unpredictable, meaning the number or order of columns can change at any time. The content sh ...

Issue with $_POST['projectSubmit'] not functioning as expected

I'm having trouble with echoing a JavaScript script after hitting the submit button. Instead of working, it just closes the modal and refreshes the page. I tried using `if($_POST['projectSubmit'])` instead of enclosing it in `isset()`, but i ...

What causes my NextJS code to execute multiple times and how can I prevent this from happening?

Struggling to integrate my frontend and backend for a webapp, I encountered an issue where multiple entries are created in the database when a user registers. Upon inspecting with console.log, it appears that my NextJS code is being executed repeatedly. I ...

Choosing a date results in an object being selected, not just the dates themselves

When I choose dates and click the filter button, the startDate and endDate are both in object form and I'm struggling to extract the selected days. I've attempted to access the properties within the object, but haven't been able to retrieve ...

capturing the value of a button during the onChange event

I'm currently trying to retrieve the button value within an onChange event. My goal is to then bind this value to state, but unfortunately, I am receiving an empty value. <button onChange={this.handleCategoryName} onClick={this.goToNextPage}> ...

Encountering an issue of THREE.EventDispatcher being undefined while trying to create a THREE.OrbitControls instance using THREE.js, THREE.OrbitControls, and TypeScript

Attempting to delve into typescript alongside three.js, I've encountered a perplexing error that has me stumped. The root of the issue lies within the init function where I initialize a new THREE.OrbitControls controller. Utilizing the setup provided ...

Received a collection of null values within the Semantic UI search dropdown

In my rails + angular application, I am utilizing semantic ui. There is a search dropdown that displays undefined values when typing the letter s, but works fine for other single letters. Strangely, no server request is made when typing the letter s, and I ...

Utilizing numerous occurrences of an npm package

Currently working on integrating handlebars as a view engine. I am looking to have multiple instances of Handlebars in order to cater to different users with different helpers/partials. Can someone kindly share an example or guide me on how to achieve th ...