Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <template iterate="..."> and <template repeat="...">

Tags:

dart

I've seen a few Dart examples/tutorials that look like <template iterate="thing in collection"> and others that use <template repeat="thing in collection">. They seem to do exactly the same thing. What's the difference between them and why is one recommended instead of the other in a given situation?

like image 659
Tyler Avatar asked Dec 27 '22 03:12

Tyler


1 Answers

Here's straight from the changelog:

Added 'template-repeat' that, unlike template-iterate, if used as an attribute it repeats the tag instead of the children of the tag.

The reason is that following HTML is invalid for most HTML parsers:

<select>
  <template iterate='name in results'>
    <option>{{name}}</option>
  </template>
</select>`

template tag is not allowed within select, so the solution is to use:

<select>
  <option template repeat='name in results'>{{name}}</option>
</select>

template repeat was added recently (April 2013), and it will replace template iterate eventually, AFAIK, but at the moment both are supported.

like image 183
Zdeslav Vojkovic Avatar answered Jan 31 '23 11:01

Zdeslav Vojkovic