Understanding Polymer data-binding and HTML tags

好久不见. 提交于 2019-12-02 19:08:40

问题


I'm new to Polymer and while testing data-binding, I discover that I have to encapsulate double-mustache expressions within HTML tags (for example <span>{{var}}</span>).

If not, variable is simply not expanded and printed as is.

An exemple (from Polymer Quick Tour), with a line more to show this behaviour. You can also find it on Plunker.

<dom-module id="name-tag">
  <template>

    <!-- Will print : This is {{owner}}'s name-tag element. -->
    This is {{owner}}'s name-tag element.<br />

    <!-- Will print : This is Daniel's name-tag element. -->
    This is <b>{{owner}}</b>'s name-tag element.
  </template>
</dom-module>

<script>
Polymer({
  is: "name-tag",
  ready: function() {
    // set this element's owner property
    this.owner = "Daniel";
  }
});
</script>

Did I miss something on the documentation, or is this some kind of bug ?

To the ones that reads this question today
This behavior seems to have been fixed, in the example on Plunkr, there is no problem anymore.


回答1:


According to the docs :

The binding annotation must currently span the entire content of the tag.

This means you currently have to wrap your bindings in a tag as you did in this example:

This is <b>{{owner}}</b>'s name-tag element.

I expect in the future this will be changed so that you don't have to wrap bindings in a tag.



来源:https://stackoverflow.com/questions/30711099/understanding-polymer-data-binding-and-html-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!