question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to pass Objects as properties

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

71reactions
thepasslecommented, Nov 2, 2018

You should pass it down as a property like so:

<list-items .todoList=${this.todoList}></list-items>

You can see a similar example here.

11reactions
LarsDenBakkercommented, May 21, 2018

@ashubham That’s how attributes work, properties are regular js properties. When using lit-element, saying <foo-element foo=${myObject}> will under the hood do fooElement.foo = myObject in JS.

Saying <foo-element foo$=${myObject}> tells lit to set an attribute instead of a property, making it do fooElement.setAttribute('foo', myObject) under the hood.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found