AnthonyNahas / ngx-linkifyjs

Angular V8 wrapper for linkifyjs - library for finding links in plain text and converting them to HTML <a> tags via linkifyjs
https://anthonynahas.github.io/ngx-linkifyjs
MIT License
42 stars 20 forks source link

Module with providers #186

Open daen1on opened 11 months ago

daen1on commented 11 months ago

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 commented 11 months ago

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);
}

}

}**