【问题标题】:Polymer 1.x insert image with paper-input带有纸张输入的 Polymer 1.x 插入图像
【发布时间】:2018-07-13 23:40:11
【问题描述】:

这是我的情况 - 每当出现纸张输入错误时,我都想显示带有错误信息的图像。所以我想生成看起来像这样的代码

<paper-input-error ng-if="isError">{{errorMessage}}
    <iron-icon icon="icons:warning"</iron-icon>
</paper-input-error>

我正在尝试使用 ::after 标记使用 css 添加代码

<style>
   paper-input-error::before{
     content:'<iron-icon icon="icons:warning"</iron-icon>';   
   }
<style>

但这不起作用。最好的方法是什么?

【问题讨论】:

    标签: html css image css-selectors polymer


    【解决方案1】:
    // import paper-input-error
    <dom-module id="element-name">
    
          <template>
            <style>
              /* CSS rules for your element */
            </style>
    
            <!-- local DOM for your element -->
    
            <paper-input-error ng-if="isError">{{errorMessage}}
               <iron-icon icon="icons:warning"</iron-icon>
            </paper-input-error>
          </template>
    
          <script>
            // element registration
            Polymer({
              is: "my-input-error",
    
              // add properties and methods on the element's prototype
    
              properties: {
                // declare properties for the element's public API
                isError: {
                  type: Boolean,
                  value: false
                },
                errorMessage: {
                  type: String,
                  value: 'Error!'
                }
              }
            });
          </script>
    
        </dom-module>
    

    【讨论】:

    • 那么每次在特定元素之后添加 html 的方法是什么?
    • 但是每当我使用纸张输入错误时,如何自动添加图像?在我的项目中出现纸张输入错误后,我不想更改代码以添加 标签。
    • 见上文 - 我需要自动生成此代码
    • 哦,所以要扩展paper-input-error,看更新
    • 太棒了!谢谢你。我希望不要创建自定义元素,但这是一个干净的解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多