5

How do I get the specific HTML dom element passed through a binding. Sorry if this is hard to understand, here's the code.

donut-chart.html

<div class="donut-chart" (donut)="$element"></div>

How do I pass the div element to donut?

This is the TS

dount-chart.ts

@Component({
  selector: 'donut-chart',
  template: require('./donut-chart.html'),
  directives: [Widget, MorrisChart],
  encapsulation: ViewEncapsulation.None,
  styles: [require('./donut-chart.scss')]
})
export class DonutChart implements OnChanges{
  @Input() height: number = 300;
  @Input() data: any[] = [{label: 'loading', value: '0', color: '#eee'}];

  morris3Options: any;
  donut: any;

  render(): void {
    jQuery(this.donut).css({height: this.height}); // safari svg height fix
    window['Morris']['Donut']({element: this.donut}, this.morris3Options);
  }

I want the donut variable to be the element without using class/id. I need to use multiple donuts and jQuery, so I need a way to get the unique donut.

1 Answer 1

5
<div #someElement></div>
<div class="donut-chart" (donut)="someElement"></div>

it can also be the current element

<div #someElement class="donut-chart" (donut)="someElement"></div>
Sign up to request clarification or add additional context in comments.

4 Comments

It has to be unique. I'm going to have multiple on the screen at once.
Please update your question and add the code that demonstrates how you have multiple on the screen. What element do you want to pass? Can you please provide more context? Perhaps there are other ways to accomplish what you want. Where does the donut event come from?
Ahh, so should I be using square brackets? There's a lot to it, but I was just wondering if there was a way to pass the element that you are binding to by using the HTML element instead of class/id. If not, I will look for a different way.
Sorry, I don't understand the later parts of your comment. If donut is an @input() instead of an event, then you need to use [donut]. If you want the element of the current component, then you can inject it, but IMHO it doesn't make much sense without more information. I saw your edit but it needs more context. Where is the <div>, where is the donut:any and render() method? How are they related (same component, different components, siblings, parent-child, ...)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.