K
K
Konstantin2021-03-03 15:00:54
Angular
Konstantin, 2021-03-03 15:00:54

How to initialize Angular service, custom class from component?

I am using Angular Elements

In my application I have a loadable component as a MapComponent. There is also a MapCore base class that contains all the domain logic:

class MapCore {
   constructor (props: Props) {
       // Конфиг здесь
   }
}

This main class should be shared across the entire Angular application. So I can make it injectable and register it in the root.

I need to set up this class manually from a component like so I use it like:

@Component({
  селектор: 'map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent {
    @Input () props: Props;
    @Input () center: Center;
    ngOnInit () {
         this.map = MapCore (this.props);
    }
}

I need this because when I get the custom element, I can pass parameters to the tag to customize the map:

<map-root center = "56,90" props = "props">
My question is how to configure the service in my case, is it a new custom MapCore class from a component and application share?

Could you share your experience on how to solve this problem?

Final result. Use the angular app on another page. By placing a component tag and passing parameters to initialize the map. In fact, embedding like Google maps.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question