You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular实现懒加载后背景视频无法加载的问题求助

Angular懒加载后背景视频加载异常排查

实现Angular懒加载后,背景视频出现以下异常:

  • 视频无法正常加载
  • 偶尔加载成功,但未按设置静音
  • 刷新页面后再次无法加载

添加懒加载前视频能正常播放,已确认视频路径正确。

视频HTML代码

<video class="background-video" autoplay loop muted>
  <source src="assets/main-page-pc.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>  

项目配置说明

  • 创建项目时未使用ng new web-name --no-standalone,手动创建了app-routing.module.ts
  • 网站所有内容都在Home组件(对应home.module.ts)中,未使用默认的app.component

路由配置代码

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule) // Lazy loading the home module
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

home.module.ts

@NgModule({
  declarations: [HomeComponent],
  imports: [
    CommonModule,
    RouterModule.forChild([{ path: '', component: HomeComponent }])
  ]
})

额外提示信息

每次执行ng serve时会收到如下提示:

Watch mode is enabled. Watching for file changes...
NOTE: Raw file sizes do not reflect development server per-request transformations.

恳请帮忙排查问题原因。

内容的提问来源于stack exchange,提问作者Miguel G.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 02:42:41