-2

In angular 1 what we can do is

var elem = document.getElementById('#someid');
$compile(elem)($scope);

and this works like charm. But i'm unable to find equivalent of above in angular 2. I'm really stuck.

To give you overview, i m using a library handsontable which is a javascript library and adds different elements to dom. Now i have element out of angular scope which i now want to include in angular scope

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Amitpal Rawat
  • 116
  • 1
  • 5

1 Answers1

0

I would suggest you can upgrade to Angular 4 which is most stable version and it have backward compatability.You can use ComponentFactoryResolver as an alternative for $compile in Angular 4

https://fromjami.com/2017/06/26/load-components-dynamically-at-runtime-in-angular-4/

https://angular.io/guide/dynamic-component-loader

In your case you can create a component with an html that you want to compile at runtime

Jameel Moideen
  • 7,542
  • 12
  • 51
  • 79
  • thanks! but i have read this document. my problem is i have an element with me and i want to compile it – Amitpal Rawat Jul 04 '17 at 20:55
  • @AmitpalRawat put that html in a component and load it. It will compile on runtime – Jameel Moideen Jul 04 '17 at 20:58
  • It will be compiled in compile time not runtime since we have to add it to entryComponents – yurzui Jul 04 '17 at 20:58
  • @XAVI .. okay to give you overview, i m using a library handsontable which is a javascript library and adds different elements to dom. Now i have element out of angular scope which i now want to include in angular scope – Amitpal Rawat Jul 04 '17 at 21:05
  • @AmitpalRawat I would suggest please edit your question and add relevant information to the question like above.So you will get good solution and answers.And also there is no concept of scope in Angular JS2 like Angular 1.0. – Jameel Moideen Jul 04 '17 at 21:09
  • @XAVI thanks !! i know there is no scope. but i just need to tell angular that hey look i have added something new can you please compile it – Amitpal Rawat Jul 04 '17 at 21:17