0

我正在尝试延迟加载第三方库,但如果有人有任何想法请分享,我找不到任何解决方案。

4

1 回答 1

0

只需添加导入,然后添加到 3rd 方库(位于assests文件夹中)的相对路径,其余的事情将由Angular CLI.

第三方组件.ts

import { Component, OnInit } from '@angular/core';    
import '../../../../assets/3rd_Party_library.js';

@Component({
  selector: 'app-thirdParty',
  templateUrl: './thirdParty.component.html',
  styleUrls: ['./thirdParty.component.css']
})
export class ThirdPartyComponent implements OnInit {

  constructor() { }

  ngOnInit() { }    
}

第三方路由.module.ts

import { ThirdPartyComponent } from './thirdParty/thirdParty.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [{
  path: '',
  component: ThirdPartyComponent
}];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ThirdPartyRoutingModule { }

第三方模块.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';    
import { ThirdPartyRoutingModule } from './thirdParty-routing.module';
import { ThirdPartyComponent } from './thirdParty/thirdParty.component';

@NgModule({
  imports: [
    CommonModule,
    ThirdPartyRoutingModule
  ],
  declarations: [ThirdPartyComponent]
})
export class ThirdPartyModule { }
于 2021-09-28T08:17:33.447 回答