The following code works as expected in DartPad, demonstrated below:
void main() {
Element e = querySelector('table');
String someValue = 'hello, world';
int anotherValue = 23958;
Element row = new Element.tr()
..appendHtml('''
<td>$someValue</td>
<td>$anotherValue</td>
''');
e.append(row);
}
DartPad
However, when I compile the same code using dart2js (dart2js -c -o app.js app.dart
) and run it on the same page, the created <td>
's are completely removed, and I end up with:
<table>
<tr>hello, world 23958</tr>
</table>
The same issue occurs when the actual .dart file is used in <script src="...">
with Dartium (v39.0.2171.0 x64). I'm on Dart v1.11.1.
Some testing:
..appendHtml('''
<td></td>
<td>hi</td>
''');
Yields:
<table>
<tr>hi</tr>
</table>
This gives the same as above:
..appendHtml('<td>hi</td>');
The only way I could get it to give me what I want is:
..append(new Element.td()..text = someValue)
..append(new Element.td()..text = anotherValue.toString());