Get a component named In AngularJS

I am creating a ModalService in AngularJS 1.6.3, where I would like to pass the name of the component, which will then be displayed in modal format.

Note. I am using ES2015.

Here is my component (where templateis a simple html file, and controlleris an empty class):

export default angular.module('editEntryModal', [])
    .component('editEntryModal', {
        restrict: 'E',
        bindings: {},
        template,
        controller
    })
    .name;

Then I have ModalServiceone that has a method show. This is where I am trying to get a link to the above component:

class ModalService {
    constructor($injector) {
        this.$injector = $injector;
    }

    show(options) {
        // this.$injector.get(options.component)
    }
}

I tried using this.$injector.get(options.component), but it does not work. It gives an errorUnknown provider: editEntryModalProvider <- editEntryModal

This is where mine is called ModalService:

this.ModalService.show({
    component: 'editEntryModal'
})

Is there a way to access a component using its name?

+4
source share

Source: https://habr.com/ru/post/1673919/


All Articles