Add elementRef to element during programatic creation


#1

Is there a way to add an elementRef to an element when creating it in code and not template?

  const gridLayout = new GridLayout();
      gridLayout.elementRef = 'foo'
  this.cl.addChild(gridLayout);

I need to be able to get the element in a function upon an event of drag and drop. Or can I get a ref to an element using some sort of getById like in core?


#2

Why don’t you directly set Id and use getViewById later?


#3

OK, I saw core examples doing that but all of the angular ones I see show using a ref and @ViewChild.


#4

Then I believe you should create the elements too in Angular way using Renderer.