Not so long ago, I began to study angular, and in the course of studying I had an idea to create a user script containing an application that should be displayed on a specific page of a third-party site. The page itself does not use angular, and I need, for example, to replace the usual html-form on it with an interface with support for ajax. The problem is that the changes on the page must be done after it is loaded. If I used simple JS, I would do something like this:

document.querySelectorAll('#element')[0].innerHTML = 'Мой_код_формы' 

But what about angular? I have studied the information about dynamic components, but the problem is that they can be added only to other components, while the loaded page itself is not a component. Therefore, I cannot add any component to the page using ViewContainerRef.

Ideally, I need to create a service that creates the necessary component right in the right place in the raw DOM (for example, in the DIV with the necessary id), since many different components are planned. Is there such a possibility in principle, and if so, how to do it?

  • to replace even the usual form with the form of angular - you need to pull all the sources behind you, i.e. @angular/(core|common) and compiled components / pipes / directives, it follows the question whether you need it? - overthesanity
  • The form was voiced as an example. In fact, I'm going to completely redo the interface, making it almost-SPA. In addition, it is an excellent and non-trivial practice. Therefore, yes, you still need :) - Denis Kirin
  • > "The form was voiced as an example" - no matter what was announced, the answer will be the same that you would not try to implement, there is still @angular/elements , but very raw still - overthesanity
  • Did I understand you correctly that the implementation of such an idea using angular is impossible? - Denis Kirin
  • one
    possible, but you have to dig into the microfronted theory, now around this big hyip, but there is little practical information, in principle, @angular/elements can solve your problem - overthesanity February

0