• Angular之装饰器使用案例


    /**
     * Auto log
     * Auto unsubscrible
     */
    export function AutoComponent(obs$ = []) {
      return function (constructor: Function) {
        console.log(constructor, "log");
        const original_Init = constructor.prototype.ngOnInit;
        constructor.prototype.ngOnInit = function () {
          console.log("Enter page " + this.name, "log");
          if (original_Init) {
            original_Init.apply(this);
          }
        };
        const origial_Destroy = constructor.prototype.ngOnDestroy;
        constructor.prototype.ngOnDestroy = function () {
          for (const prop in this) {
            const property = this[prop];
            if (
              property &&
              typeof property.unsubscribe === "function" &&
              !obs$.includes(property)
            ) {
              obs$.push(property);
            }
          }
          for (const ob$ of obs$) {
            ob$.unsubscribe();
          }
          console.log(origial_Destroy, "log");
          if (origial_Destroy) {
            origial_Destroy.apply(this);
          }
          console.log("Exit page " + this.name, "log");
        };
      };
    }
    人生旅途,边走边看...
  • 相关阅读:
    进程与线程的区别与联系
    c 指针兼容性问题
    柔性数组
    Makefile之wildcard
    shell编程笔记1
    linux下gcc编译的参数详细说明
    的理解
    URL与URI的区别
    Log4J积累
    linux 查看磁盘、文件夹、文件大小(df du)
  • 原文地址:https://www.cnblogs.com/dming4/p/12821845.html
Copyright © 2020-2023  润新知