当前位置: 首页 > news >正文

网站做qq链接代码如何购买云服务器

网站做qq链接代码,如何购买云服务器,怎样进入网站的后台,网站备案 工信部引言有时候需要根据URL来渲染不同组件#xff0c;我所指的是在同一个URL地址中根据参数的变化显示不同的组件#xff1b;这是利用Angular动态加载组件完成的#xff0c;同时也会设法让这部分动态组件也支持AOT。动态加载组件下面以一个Step组件为示例#xff0c;完成一个3个…引言有时候需要根据URL来渲染不同组件我所指的是在同一个URL地址中根据参数的变化显示不同的组件这是利用Angular动态加载组件完成的同时也会设法让这部分动态组件也支持AOT。动态加载组件下面以一个Step组件为示例完成一个3个步骤的示例展示并且可以通过URL user?stepstep-one 的变化显示第N个步骤的内容。1、resolveComponentFactory首先还是需要先创建动态加载组件模块。import { Component, Input, ViewContainerRef, ComponentFactoryResolver, OnDestroy, ComponentRef } from angular/core;Component({selector: step,template: })export class Step implements OnDestroy {private currentComponent: ComponentRef;constructor(private vcr: ViewContainerRef, private cfr: ComponentFactoryResolver) {}Input() set data(data: { component: any, inputs?: { [key: string]: any } } ) {const compFactory this.cfr.resolveComponentFactory(data.component);const component this.vcr.createComponent(compFactory);if (data.inputs) {for (let key in data.inputs) {component.instance[key] data.inputs[key];}}this.destroy();this.currentComponent component;}destroy() {if (this.currentComponent) {this.currentComponent.destroy();this.currentComponent null;}}ngOnDestroy(): void {this.destroy();}}抛开一销毁动作不谈的话实际就两行代码let compFactory this.cfr.resolveComponentFactory(this.comp);利用 ComponentFactoryResolver 查找提供组件的 ComponentFactory而后利用这个工厂来创建实际的组件。this.compInstance this.vcr.createComponent(compFactory);这一切都非常简单。而对于一些基本的参数是直接对组件实例进行赋值。for (let key in data.inputs) {component.instance[key] data.inputs[key];}最后还需要告诉Angular AOT编译器为用户动态组件提供工厂注册否则 ComponentFactoryResolver 会找不到它们最简单就是利用 NgModule.entryComponents 进行注册。NgModule({entryComponents: [ UserOneComponent, UserTwoComponent, UserThirdComponent ]})export class AppModule { }但这样其实还是挺奇怪的entryComponents 本身可能还会存在其他组件。而动态加载组件本身是一个通用性非常强因此把它封装成名曰 StepModule 挺有必要的这样的话就可以创建一种看起来更舒服的方式。NgModule({declarations: [ Step ],exports: [ Step ]})export class StepModule {static withComponents(components: any) {return {ngModule: StepModule,providers: [{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: components, multi: true }]}}}通过利用 ANALYZE_FOR_ENTRY_COMPONENTS 将多个组件以更友好的方式动态注册至 entryComponents。const COMPONENTS [ ];NgModule({declarations: [ ...COMPONENTS ],imports: [StepModule.withComponents([ ...COMPONENTS ])]})export class AppModule { }2、一个示例有3个Step步骤的组件分别为// user-one.component.tsimport { Component, OnDestroy, Input, Injector, EventEmitter, Output } from angular/core;Component({selector: step-one,template: Step One Componentparams value: {{step}}})export class UserOneComponent implements OnDestroy {private _step: string;Input()set step(str: string) {console.log(Input step: str);this._step str;}get step() {return this._step;}ngOnInit() {console.log(step one init);}ngOnDestroy(): void {console.log(step one destroy);}}user-two、user-third 略同这里组件还需要进行注册const STEPCOMPONENTS [ UserOneComponent, UserTwoComponent, UserThirdComponent ];NgModule({declarations: [ ...STEPCOMPONENTS ],imports: [StepModule.withComponents([ ...STEPCOMPONENTS ])]})export class AppModule { }这里没有 entryComponents 字眼而是为 StepModule 模块帮助我们动态注册。这样至少看起来更内聚一点而且并不会与其他 entryComponents 在一起待东西越多越不舒服。最后还需要 UserComponent 组件来维护步骤容器会根据 URL 参数的变化利用 StepComponent 组件动态加载相应组件。Component({selector: user,template: })export class UserComponent {constructor(private route: ActivatedRoute) {}stepComp: any;ngOnInit() {this.route.queryParams.subscribe(params {const step params[step] || step-one;// 组件与参数对应表const compMaps {step-one: { component: UserOneComponent, inputs: { step: step } },step-two: { component: UserTwoComponent },step-third: { component: UserThirdComponent },};this.stepComp compMaps[step];});}}非常简单的使用而且又对AOT比较友好。总结文章里面一直都在提AOT其实AOT是Angular为了提供速度与包大小而生的按我们项目的经验来看至少在包的大小可以减少到 40% 以上。当然如果你是用angular cli开发那么当你进行 ng build --prod 的时候默认就已经开启 AOT 编译模式。
http://www.zqtcl.cn/news/168864/

相关文章:

  • 哪一个军事网站做的比较好今天第四针最新消息
  • 黄页网站推广app软件查企业公司用什么软件
  • 网站设计机构培训全自动网页制作系统源码
  • 外贸网站建设收益深圳建设厅官网
  • 跟网站开发有关的内容东莞市生态环境局
  • dw软件做的东西怎么在网站用网站备案抽查通过
  • 重庆建设集团网站首页wordpress主题inn
  • 对京东网站建设的总结湖北做网站的
  • 杭州网站开发后端招郑州工装定制
  • 网站搭建论文filetype ppt 网站建设
  • 个人做营利性质网站会怎么样如何引用网站上的资料做文献
  • 新网站制作市场泰安做网站哪家好
  • 常熟苏州网站建设flash如何制作网站
  • 电商网站都是用什么做的网站服务器维护方案
  • 简述企业网站建设的流程手机怎么自己做网页
  • 网站备案信息管理呼图壁网站建设
  • 网站建设学习资料开发一套软件需要多少钱
  • 大庆网站设计衡阳seo网站推广
  • 基层科普网站建设的现状自己做的网站怎样链接数据库
  • 网站建设工程师的职位要求化妆品行业网站开发
  • 做海报有什么素材网站知乎什么样的蓝色做网站做好看
  • 餐饮网站建设网站wordpress优酷视频插件下载
  • 什么网站做广告效果好wordpress中文cms
  • seo与网站优化广州洲聚网站开发
  • 建一个自己用的网站要多少钱北京网站建设价格天
  • 免费做婚礼邀请函的网站如何设定旅游网站seo核心关键词
  • 网上做问卷调查赚钱哪些网站好全flash网站制作
  • 个人网站备案核验单填写wordpress登录安全插件下载
  • 拖拽做网站cms系统设计
  • 村建站什么部门网站建设步骤图