Add elementRef to element during programatic creation


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';

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?


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


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


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