How to pass Objects as properties
See original GitHub issueI am following a controller as attribute pattern (coming from Angular world):
const DEFAULT_TEXT = 'This is the default Text';
export class ButtonController {
constructor(public text,
public color,
public onClick: () => void) {
}
public reset() {
this.text = DEFAULT_TEXT;
}
}
export class ButtonComponent extends LitElement {
static get properties() {
return {
ctrl: ButtonController
};
}
}
customElements.define('bk-button', ButtonComponent);
Any ideas on how can I pass an instance of ButtonController
to <bk-button ctrl=btnCtrl></bk-button>
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to pass an object property as a parameter? (JavaScript)
use [] with a string to pull out properties from objects dynamically. var a = { foo: 123 }; a.foo // 123 a['foo']...
Read more >How to pass an object as a parameter in JavaScript function?
We can pass an object to a JavaScript function, but the arguments must have the same names as the Object property names.
Read more >Chapter 7. Object arguments: functions working with objects
Just as passing objects to functions as arguments is an efficient way of moving information to where it's needed, so is using objects...
Read more >Working with objects - JavaScript - MDN Web Docs - Mozilla
This chapter describes how to use objects, properties, and methods, and how to create your own objects. Creating new objects. You can create...
Read more >How to Pass Properties Object to Child Component | Pluralsight
In this guide, we'll learn about props in React, including how to declare them and how to pass a properties object to a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You should pass it down as a property like so:
<list-items .todoList=${this.todoList}></list-items>
You can see a similar example here.
@ashubham That’s how attributes work, properties are regular js properties. When using lit-element, saying
<foo-element foo=${myObject}>
will under the hood dofooElement.foo = myObject
in JS.Saying
<foo-element foo$=${myObject}>
tells lit to set an attribute instead of a property, making it dofooElement.setAttribute('foo', myObject)
under the hood.