Experience the convenience of lazy-loading in Angular Ivy: The InjectionToken ng-select-selection-model provider is not available

Issue Description I have integrated angular's IVY compiler and lazy-loading feature according to the tutorial found here:

However, when I attempt to lazy-load a module and add an instance of a component to my application, the ng-select element is not visible in the component. The console displays the following error message:

core.js:6354 ERROR NullInjectorError: R3InjectorError(AppModule)[InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model]:
    NullInjectorError: No provider for InjectionToken ng-select-selection-model!
    at NullInjector.get (http://localhost:4200/vendor.js:8736:27)
    ...
    at Object.get (http://localhost:4200/vendor.js:38095:35)
    at getOrCreateInjectable (http://localhost:4200/vendor.js:12876:39)
    ...
    at getNodeInjectable (http://localhost:4200/vendor.js:13021:44)

To Reproduce the Issue 1. Clone the example repository using the command:

git clone https://github.com/boltex/ivy-lazyload-test
2. Install all dependencies by running: npm install 3. Start the server by running: ng serve

Expected Outcome Upon loading the program locally through ng serve and clicking on the "Lazy load module & add instance of component below" button, new components should be added with the ng-select element included. However, this does not happen and the specified error is displayed in the console.

Note Please disregard the initial error in the console mentioning: Uncaught TypeError: ng.probe is not a function. This is a common error associated with Angular 9 as augury assumes dev mode is active if window.ng exists, which is not the case with IVY.

My Environment Information - Operating System: Windows 10 - Browser: Chrome - Version: 78.0.3904.108 (Official Build) (64-bit)

Thank you for your time and attention towards resolving this issue!

Answer №1

Thanks to @HeroDev and their 'hero-loader' component, I was able to find a solution. (For more details on the techniques used, check out their concise source code here: https://github.com/herodevs/herodevs-packages/tree/master/projects)

The approach I had been using wasn't completely compatible with all methods of incorporating components, whether third-party or not, into an existing application through lazy-loading (without routing).

I have now updated my repository https://github.com/boltex/ivy-lazyload-test with a functional example. This demonstrates how you can easily add and remove various modules and components within an open application without having to modify routes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sharing data between two components in Angular 7

The Address object values are not being retrieved as expected when requesting from the credit card component to a function called getAddress() in a config service that holds the value. Instead of the updated values, I am getting the initial values. Below i ...

How can I prevent an Angular 2+ app from loading until the APP_INITIALIZER has completed its execution?

While I have managed to call a service before the root component loads, I am struggling to find a way to make the whole app wait until the service completes successfully. Essentially, I am looking for a way to make it a synchronous call. The service is loa ...

Why is my ASP.NET Core Crud request failing with incorrect method matching?

I am facing an issue with the third method in my Angular ASP.NET Core Controller. The first two methods work fine, but the GetBookItemsByTitle does not seem to be firing correctly. As I am still learning, I believe my mistake here is obvious. /// <summ ...

Angular 2 routing for dynamic population in a grid system

My website is compiling correctly, however, in the Sprint dropdown menu where I have set up routing... <a *ngFor = "let item of sprint;" routerLink = "/Summary" routerLinkActive = "active"> <button *ngIf = "item.Name" mat-menu-item sty ...

Issue encountered with ng-include compatibility in Angular 5

Just getting started with Angular and working on a small test project using Angular 5 and Visual Code. I'm attempting to use ng-include but the template is not displaying. src add-device add-device.component.html add-device.com ...

Tips for transforming a scroll element into the viewport using Angular 2+

This is a sample Here is a component with a list of items: class HomeComponent { text = 'foo'; testObject = {fieldFirst:'foo'}; itemList = [ '1', '2', '3', & ...

Versions of Angular that are compatible with Ionic 2 (do not have an exported member)

How do I determine the compatible Angular version for each Ionic version? I keep encountering errors like "has no exported member." For example: The module ".../node_modules/@angular/core/index" does not have an exported member called InjectionToken. The ...

Encountered an error while attempting to update an object: Unable to read property 'push' of undefined

Encountering an issue while attempting to update an object with additional information, receiving an error message stating 'property \'push\' of undefined'. /*Below is the object model in question:*/ export class Students { ...

Adjusting the timing of a scheduled meeting

Is there a way for me to update the time of a Subject within my service? I'm considering abstracting this function into a service: date: Date; setTime(hours: number, mins: number, secs: number): void { this.date.setHours(hours); this.date.s ...

How to integrate custom plugins like Appsee or UXCAM into your Ionic 2 application

Struggling to integrate either Appsee or UXcam into my project. I attempted to import the plugin like this, but it didn't work: // import { Appsee } from '@ionic-native/appsee'; I read somewhere that you need to declare the variable for Ty ...

Having trouble getting a constructor to function properly when passing a parameter in

Here's the code snippet I'm working with: import {Component, OnInit} from '@angular/core'; import {FirebaseListObservable, FirebaseObjectObservable, AngularFireDatabase} from 'angularfire2/database-deprecated'; import {Item} ...

Having trouble displaying real-time camera RTSP streaming using Angular

I am currently in the process of developing a web application using Angular and I need to incorporate a window that displays live RTSP streaming. Upon conducting research, I discovered that this can be achieved by utilizing the JSMpeg JavaScript library. ...

Utilizing ngClassEven and ngClassOdd in Angular 2 for Improved Styling

I attempted to replicate the behavior of ng-class-even and ng-class-odd (originally from Angular 1) in my Angular 2 application. Below is the code I wrote and it's functioning correctly, but I'm curious if there are alternative methods to achiev ...

Unable to connect with '*ngFor' because it is not a recognized attribute of 'div'

I attempted to bind a value for filter in *ngFor, but it didn't work correctly. How can I successfully bind data to ngFor? Source code is shown below: In my .ts file, menuIcons:any[]; public pageName:any = "projects"; this.menuIcons=[{ ...

Navigating back to the login page in your Ionic V2 application can be achieved by utilizing the `this.nav

Running into an issue with navigating back to the login screen using Ionic V2. Started with the V2 tabs template but added a custom login page, setting rootPage = LoginPage; in app.components.ts. When the login promise is successful, I used this.nav.setR ...

The modal feature on ng-bootstrap.github.io is failing to function properly when used with the Bootstrap3 CSS

Struggling to understand why the modal displays when using Bootstrap 4 with ng-bootstrap, but not displaying with Bootstrap 3. ...

Retrieve the attributes of a class beyond the mqtt callback limitation

Currently, I am utilizing npm-mqtt to retrieve information from a different mqtt broker. My objective is to add the obtained data to the array property of a specific class/component every time a message is received. However, I'm facing an issue wher ...

Stop the inheritance of static components in a feature module by protecting the router-outlet

I am in the process of dividing my app into multiple feature modules. Currently, I am using only the router-outlet inside a component within a feature module. However, this approach brings along all the static components such as the navbar and footer. How ...

Is there a way to access the value of a variable from a .ts file within a .scss file?

Utilizing a css-only pie chart, I am looking to incorporate the value of this.performance in my scss to determine the percentage. How can I manipulate my scss file from .ts file? Below is a snippet of my css code in scss: $configs: ( chart-one: ( sv ...

The method to permit a single special character to appear multiple times in a regular expression

I am currently working on developing a REGEX pattern that specifically allows alphanumeric characters along with one special character that can be repeated multiple times. The permitted special characters include ()-_,.$. For instance: abc_def is conside ...