Working old Web UI code:
<template instantiate="if view == 'dashboard'">
Not working Polymer code:
<p>{{view}}</p> <-- this is ok, prints: dashboard
<template if="{{view == 'dashboard'}}"> <-- not work, if I change code to use bool property something like {{showDashboard}} then works ok.
What is the correct syntax? I can't find any example of instantiate with string comparison.
* *Edit. More details: Dart SDK version 0.7.3.1_r27487
html:
<p>int: {{score}}</p>
<template bind if="{{score == 4}}">
<p>ins int: {{score}}</p>
</template>
<p>String: {{view}}</p>
<template bind if="{{view == 'dashboard'}}">
<p>ins String: {{view}}</p>
</template>
<p>bool: {{showp}}</p>
<template bind if="{{showp}}">
<p>ins bool: {{showp}}</p>
</template>
dart:
class AppModel extends Object with ObservableMixin {
@observable String view = "dashboard";
@observable int score = 4;
@observable bool showp = true;
}
void main() {
query("#templ").model = new AppModel();
}
And output:
int: 4
String: dashboard
bool: true
ins bool: true
Jacek, this works for me. In one of my apps, I have the following use of conditional rendering (variable names changed to match your example):
<template bind if="{{view == 'dashboard'}}">
<p>{{view}}</p>
</template>
In this snippet, {{view}} renders only when score equals 4:
<template bind if="{{score == 4}}">
<h2>Score: {{score}}</h2>
</template>
And the conditionals work even if you change bind if
to just if
.
Can you post more code? Perhaps the problem lies elsewhere.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.