聚合物2.x。扩展聚合物元素的属性

Polymer 2.x. Extend properties of polymer element

使用 Polymer 2.x 语法创建一个 class 扩展另一个 class(从 Polymer.Element 扩展),是否可以定义默认集超级 class 中的属性可以在子 class?

中覆盖

我的尝试是:

class ParentClass extends Polymer.Element
   static get properties() {
      return {
        myProperty: {
           type: String,
           value: "x"
        }
      }
   }
}

class ChildClass extends ParentClass {
   static get properties() {
      return {
        myProperty2: String
      }
   }
}

当创建 ParentClass 时,期望 myProperty == "x",而当创建 ChildClass 时,期望 myProperty == "x" 并具有额外的 属性 myProperty2。实际上,ChildClass 只有 myProperty2.

也许 ChildClass 应该调用超级 class 属性并合并属性,但我找不到调用超级 class 的方法,可能是因为它被声明为静态(?)。

您需要在 child-class 元素中导入 parent-class。然后,要访问 parent-class 的 属性,只需调用 属性 在 child-class 上,例如:this.myProperty.

您还可以覆盖 child-class 中的 属性 值。

这是 plnkr 中的演示:http://plnkr.co/edit/7kkitdcCZkbySNClxgTo?p=preview

Note: The properties and observers of a subclass(child class) are added to those defined by the superclass(parent class).

A subclass can also inherit a template from its superclass.