javascript - Attach Angular2 Component to existing element without replacing content -


i have problem migrate ng1 app ng2. load our ng1 app dynamicly , attach body or html tag of page inline directives inside. see example - plunkr .

after page load, do

angular.bootstrap(document.body, ['app']); 

directives "alive" now.

but ng2 don't know how properly. if bootstrap component body selector, replace content of page. can add ... body, our "inline" directives still outside of tag, somewhere in user content, not compiled.

the way can manage bootstrap every "inline" directive separately. bootstrap(mydirective); bootstrap first matched element on page, need "clone" directive class , dynamically set strict selector it:

var somedirective = (function (_super) {     __extends(somedirective , _super);     function somedirective () {         _super.call(this);     }      return somedirective; })(mydirective); //extend directive class somedirective['annotations'] = [  //set annotations     new component({         selector: "div[mydirective='1']", //here go     }),     new view({         template: 'mydirective.html'     }) ];  bootstrap(somedirective); 

and works - plunkr. doesn't feel right. maybe there more correct way such thing?

thanks!


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -