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 add a custom button with event emmeter ?

See original GitHub issue

Hey,

I’d like to add a custom button on each row. I achieved it dealing with the ‘html’ property and the sanitizer, but I couldn’t find a way to handle the event ? Is it possible to add an event emitter which is correctly interpreted by ng2? Bypassing HTML & JS Security ?

I can’t listen directly to the button events.

What I’m currently doing:

{
                      columns: {
                        test: {
                          title: 'fire',
                          type: 'html',
                          valuePrepareFunction: (value) => {
                            return this._sanitizer.bypassSecurityTrustHtml('<button (click)="test()">TEST</button>'); //Click listener not interpreted...
                          }
                        }
                      }
                    };

Then add an event on the table <ng2-smart-table [...] (userRowSelect)="onSelect($event)"></ng2-smart-table>

Set the selected item

onSelect(event){
    this.selectedItem=event.data._id;
  }

Then add an outside button to the table that handle the wanted event.

Thanks

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

2reactions
terrymainviscommented, Jan 11, 2017

Well it’s a way to avoid the current problem, sorry if it didn’t fit you needs.

1reaction
terrymainviscommented, Jan 11, 2017

I didn’t solve this issue, I just took one existing button (like the Edit button), and override the behavior by setting the table mode to ‘external’ and using the event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to build custom Node.js event emitters - LogRocket Blog
Create the event emitter function constructor; Add methods to the event ... Custom events occur inside the JavaScript core in Node.js.
Read more >
How to create and fire a custom event in angular
You declare a class property with the @Output() decorator and instantiate it to a new EventEmitter instance. Example from the Angular docs
Read more >
How to Custom event Emitter in Angular Calendar component
The two-way binding in Calendar can also be achieved using the custom event binding and property binding in the controls present in two...
Read more >
EventEmitter - Angular
Use in components with the @Output directive to emit custom events synchronously or asynchronously, and register handlers for those events by subscribing to ......
Read more >
Understanding Event Emitters | CSS-Tricks
We added a listener to a button click. We've subscribed to an event being emitted and we fire a callback when it does....
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