Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module with providers #186

Open
daen1on opened this issue Oct 16, 2023 · 1 comment
Open

Module with providers #186

daen1on opened this issue Oct 16, 2023 · 1 comment

Comments

@daen1on
Copy link

daen1on commented Oct 16, 2023

Bug Report or Feature Request (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

Versions

Angular 16

Repro steps

When trying to execute, angular would say "Usage without a generic type is deprecated"

The log given by the failure

Desired functionality

Mention any other details that might be useful

@daen1on
Copy link
Author

daen1on commented Oct 16, 2023

Searching through the web, In Angular 10 and later, the ModuleWithProviders type without a generic has been deprecated. This is because the Angular team wants to make the Ivy compiler the default for Angular applications, and the Ivy compiler requires that ModuleWithProviders be generic. Please update the ngx-linkify.module.ts to this:

import {CommonModule} from '@angular/common';
import {Inject, InjectionToken, ModuleWithProviders, NgModule} from '@angular/core';
import * as linkify from 'linkifyjs';
import hashtag from 'linkifyjs/plugins/hashtag';
import mention from 'linkifyjs/plugins/mention';

import {NgxLinkifyjsService} from './service/ngx-linkifyjs.service';
import {NgxLinkifyjsPipe} from './pipes/ngx-linkifyjs.pipe';
import {NgxLinkifyjsConfig} from './interfaces/ngx-linkifyjs.interface';

export const NgxLinkifyjsConfigToken = new InjectionToken('NgxLinkifyjsConfig');
export const DEFAULT_CONFIG: NgxLinkifyjsConfig = {enableHash: true, enableMention: true};

@NgModule({
imports: [
CommonModule
],
exports: [NgxLinkifyjsPipe],
declarations: [NgxLinkifyjsPipe]
})
export class NgxLinkifyjsModule {

static forRoot(config: NgxLinkifyjsConfig = DEFAULT_CONFIG): ModuleWithProviders {
return {
ngModule: NgxLinkifyjsModule,
providers:
[
NgxLinkifyjsService,
{
provide: NgxLinkifyjsConfigToken,
useValue: config
},
]
};
}

constructor(@Inject(NgxLinkifyjsConfigToken)
public config: NgxLinkifyjsConfig) {
if (config.enableHash) {
hashtag(linkify);
}

if (config.enableMention) {
  mention(linkify);
}

}

}**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant