How to get the last element of an array in Angular2 template WITHOUT LOOPING EVERYTHING?

tom10271

This question is not asking how to get access to looping variables like i, first, last but how to retrieve and set variable as TEMPLATE VARIABLES.


This is not working...

<div #lastElement="arr[arr.length-1]"></div>

So I actually need to create a local variable in component then bind it directly?

I feel lots of stuff I can do it with ng-* directives in the past are all required to hardcode in Component... Kind of degrading tbh

Günter Zöchbauer

You can't assign arbitrary values to template variables. Template variables are for references to elements and directives and locals used for structural directives.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get an element from a 2D array without looping the entire array?

How to get an array of numbers without looping

Looping over a dictionary without first and last element

How to copy the elements of the copied element into an array without looping through it?

How to get array keys value into one array with no keys and without looping?

How to get an array of specific "key" in multidimensional array without looping

std::tuple get everything except last element

How to get the last element in json array in postman

How can I get the last element of an array?

How to get last element in a MySQL JSON array?

How to get the last element of an array and show the rest?

How to get the last element of an array field in Elasticsearch

How to get last element of an array in smarty templates

In bash, how do I get the index of the last element of an array without a loop

How to get the last item of array without pop?

Get last element of an Array?

How to get element number when looping through a VBA Array

Get last element of $@ / argv / arguments array without eval

What's the best way to get the last element of an array without deleting it?

Accessing specific array element in an Angular2 Template

Angular2: What is the best way to get a reference of a template element

How to select only first and last element from an array without aggregate?

How to get past the last element and get back to the begining of an array in JS?

How to get a last element of ES6 Map without iterations?

How to get everything after last slash in a URL?

How to get everything after last slash in a URL?

Angular2: Get dimensions of DOM-Element (without ElementRef)

How to retrieve last element id of array in Angular 2

Get last element in Bash array