[Angular 8] Implement a Custom Preloading Strategy with Angular
Preloading all modules is quite an extreme approach and might not always be desirable. For instance, you don't want to preload lazy routes a user might not even have access to. Therefore, in this lesson we're going to have a look at how to define a custom preloading strategy in Angular.
custom-preloader.ts:
import { PreloadingStrategy, Route } from '@angular/router';
import { Observable, of } from 'rxjs';
import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root'
})
export class CustomPreloader implements PreloadingStrategy {
preload(route: Route, load: Function): Observable<any> {
if (route.data && route.data['preload']) {
return load();
} else {
return of(null);
}
}
}
import { CustomPreloader } from './custom-preloader'; @NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
MatSidenavModule,
BrowserAnimationsModule,
RouterModule.forRoot(
[
{
path: '',
component: HomeComponent
},
{
path: 'nyan',
loadChildren: () =>
import('./nyan/nyan.module').then(m => m.NyanModule),
data: {
preload: true
}
},
{
path: 'about',
loadChildren: () =>
import('./about/about.module').then(m => m.AboutModule)
}
],
{
preloadingStrategy: CustomPreloader //PreloadAllModules
}
)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
[Angular 8] Implement a Custom Preloading Strategy with Angular的更多相关文章
- How to: Implement a Custom Base Persistent Class 如何:实现自定义持久化基类
XAF ships with the Business Class Library that contains a number of persistent classes ready for use ...
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...
- angular 2+ 变化检测系列三(Zone.js在Angular中的应用)
在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...
- 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once
自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...
- [Angular] Implement a custom form component by using control value accessor
We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...
- [Angular Directive] Implement Structural Directive Data Binding with Context in Angular
Just like in *ngFor, you're able to pass in data into your own structural directives. This is done b ...
- How to implement a custom type for NHibernate property
http://blog.miraclespain.com/archive/2008/Mar-18.html <?xml version="1.0" encoding=&quo ...
- [Angular 2] Filter items with a custom search Pipe in Angular 2
This lessons implements the Search Pipe with a new SearchBox component so you can search through eac ...
- How to implement a custom PropertyEditor so that it supports Appearance rules provided by the ConditionalAppearance module
https://www.devexpress.com/Support/Center/Question/Details/T505528/how-to-implement-a-custom-propert ...
随机推荐
- hdu 5418 题解
第一眼看到这题,哇,这不是我刚做完的题吗?大水题!然后 这题表面很水,实际上有点坑. 题意 求经过 $ 1 - n $(不能遗漏) 并且回到 $ 1 $ 的最短路. 在看这题之前我们可以来看下这题 最 ...
- Spyder中报错: Check failed: PyBfloat16_Type.tp_base != nullptr
报错问题: 问题1:tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp ...
- OpenCV学习笔记5
OpenCV学习笔记5 图像变换 傅里叶变换 这里可以先学习一下卷积分,了解清除卷积的过程和实际意义,在看这一章节的内容. 原理: 傅里叶变换经常被用来分析不同滤波器的频率特性.我们可以使用 2D 离 ...
- 在vue中使用swiper组件
第一步:在终端的项目根目录下载安装swiper: cnpm/npm install vue-awesome-swiper --save; 第二步:在程序入口文件main.js中引用: import V ...
- Spring AOP日志实现(三)--获取访问者用户名
通过Security获取访问者用户名: 也可以通过session来获取: 整体思路:
- Docker 学习笔记(二):Dockerfile 定制镜像
镜像的定制实际上就是定制每一层所添加的配置.文件. 如果我们可以把每一层修改.安装.构建.操作的命令都写入一个脚本,用这个脚本来构建.定制镜像,那么之前提及的无法重复的问题.镜像构建透明性的问题.体积 ...
- mouseenter 与 mouseover 区别于选择
mouseover事件, 箭头在子元素移动会触发冒泡事件, 子元素的鼠标箭头可触父元素方法, 相反,mouseenter事件功能与mouseover类似, 但鼠标进入某个元素不会冒泡触发父元素方法. ...
- Markdown试试
from os import time print("haha") from os import time print("haha") time.time()! ...
- Golang官方log包详解
Golang官方log包详解 以下全是代码, 详解在注释中, 请从头到尾看 // Copyright 2009 The Go Authors. All rights reserved. // Use ...
- 查询慢SQL
可以查看当前时间访问库的所有请求SQL SELECT COUNT(*) AS c,state,info FROM `information_schema`.processlist GROUP B ...