Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 629 Bytes

File metadata and controls

56 lines (37 loc) · 629 Bytes

LWC Template Errors

Template Expression Fails

Symptom:

Invalid expression

Cause:

  • LWC templates do not allow arbitrary JavaScript.

Fix:

  • move the expression into a getter.

Bad:

<template if:true={rows.length > 0}></template>

Good:

<template if:true={hasRows}></template>
get hasRows() {
  return Array.isArray(this.rows) && this.rows.length > 0;
}

Class Binding Fails

Bad:

<div class={isSelected ? 'selected' : ''}></div>

Good:

<div class={rowClass}></div>
get rowClass() {
  return this.isSelected ? 'selected' : '';
}