我已經在一個聚合物組分如下:條件模板似乎並沒有工作
<dom-module id="ws-auth">
<template>
<template is="dom-if" if="{{screen.initial}}">
<a on-click="doLocalLogin">Local Login</a>
</template>
<template is="dom-if" if="{{screen.localLogin}}">
login screen
</template>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'ws-auth',
properties: {
screen: {
type: Object,
notify: true
}
},
attached: function() {
if (!this.screen) {
this.screen = {
initial: true
}
};
},
doLogin: function() {
this.screen = {
login: true
}
},
doLocalLogin: function() {
this.screen = {
localLogin: true
}
}
});
})();
當我點擊「本地登錄」第一模板不隱藏。我期望它隱藏起來,因爲我將屏幕設置爲一個沒有定義'初始'屬性的新對象。還有就是我努力去理解另一件事:如果我將屏幕對象
{
initial: false,
localLogin: true
}
在doLocalLogin()函數,什麼都沒有發生。
此外,您可以在if標籤中使用的表達式似乎相當有限。只有屬性似乎工作,沒有函數調用,'==='等是這樣嗎? – Janos
Plunkr:http://plnkr.co/edit/2w5ghun93mU3mSIzm8Ip?p=preview – Janos