javascript - Will this custom element work? I've taken it off Material Design lite -
class cardelement extends htmlelement { constructor() { super(); let shadow = this.attachshadow({mode: open}); let div = document.createelement('div'); let div_main = div; div_main.classname = "demo-card-square mdl-card mdl-shadow--2dp"; shadow.appendchild(div_main); let div_sec = div; div_sec.classname = "mdl-card__title mdl-card--expand"; div_sec.style.background = this.getattribute('src'); shadow.appendchild(div_sec); let h2 = document.createelement('h2'); h2.classname = "mdl-card__title-text"; h2.innerhtml = this.getattribute('text'); shadow.appendchild(h2); let div_three = div; div_three.classname = "mdl-card__supporting-text"; div_three.innerhtml = this.getattribute('support-text'); shadow.appendchild(div_three); let div_border = div; div_border.classname ="mdl-card__actions mdl-card--border"; shadow.appendchild(div_border); let anchor = document.createelement('a'); anchor.classname = "mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"; shadow.appendchild(anchor); } } customelements.define('card-element', cardelement); }
i tried make card component (https://getmdl.io/components/index.html#cards-section) custom element above given code. couldn't see appropriate output. appreciated since i've started develop applications web.
<card-element src="img.jpg" text="inside" support-text="can see i've done here!"></card-element>
and showing me error: uncaught typeerror: failed execute 'attachshadow' on 'element': provided value 'function open() { [native code] }' not valid enum value of type shadowrootmode. @ new cardelement
so let me why isn't working or how should tackling problem.
you should use simple or double quotes open
in attachshadow()
:
let shadow = this.attachshadow({mode: "open"});
Comments
Post a Comment