ändern von name und amount erfolgt über attributenänderung
attributChangedCallback wird ausgelöst wenn sich ein attribut in observedAttributes von shopping-item ändert
This commit is contained in:
1 parent
377d888221
commit
9ed72aa23e
1 file changed
+14
-2
@@ -1,5 +1,6 @@
|
||||
export class ShoppingItem extends HTMLElement {
|
||||
|
||||
static get observedAttributes() { return ["item-name", "item-amount"] }
|
||||
constructor() {
|
||||
super();
|
||||
this._rendered = false;
|
||||
@@ -40,8 +41,19 @@ export class ShoppingItem extends HTMLElement {
|
||||
|
||||
}
|
||||
|
||||
attributeChangedCallback() {
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
if (!this._rendered) return;
|
||||
if (newVal == oldVal) return;
|
||||
switch (name) {
|
||||
case "item-name":
|
||||
this.querySelector(".item__itemName").textContent = newVal;
|
||||
break;
|
||||
case "item-amount":
|
||||
this.querySelector(".item__itemAmount").textContent = newVal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user