發表文章

目前顯示的是 10月, 2020的文章

Typescript decorators 如何在 類別/屬性/方法 上標註資訊

Typescript decorators 如何在 類別/屬性/方法 上標註資訊 裝飾器(Decorators)為我們在類的聲明和成員上通過元編程語法添加標註提供 了一種方式,其實就是Java 中的annotation,只是 Decorators 除了標示還有更多功能,像是AOP… 定義Decorators 請先安裝  npm i reflect-metadata 先定義兩個 Decorators 如下 一個是類別(Clazz)用的,和屬性(Prop)用的 const metadataPropKey = 'PropInfo' ; const metadataClazzKey = 'ClazzInfo' ; // tslint:disable-next-line: typedef export function Clazz ( value: ClazzArgs ) { return (target: any ) => { Reflect.defineMetadata(metadataClazzKey, value, target); }; } // tslint:disable-next-line: typedef export function Prop ( value: PropArgs ) { return (target: any , propertyKey: string ) => { Reflect.defineMetadata(metadataPropKey, value, target, propertyKey); }; } // Class標註的參數 export interface ClazzArgs { title: string ; } // properties標註的參數 export interface PropArgs { title: string ; type : string ; } 類別和屬性的差別是參數的不同來決定的 Reflect.defineMetadata(metadataClazzKey, value, target); Reflect.defineMetadata(metadataPro

透過Angular 來開發 Google Chrome Extension 的重點設定

圖片
  透過Angular 來開發 Google Chrome Extension 的重點設定 如果沒接觸的朋友可以參考這一篇  https://medium.com/hybrid-maker/簡單來做一個-chrome-extension-2359e43f282a Google Chrome Extension Wiki 因為公司內部有個系統是用Chrome Extension,來做操作介面,然後是使用ko.js ,費了好大筆勁目前已經換成 Angular10 這邊就先來做個筆記 設定 manifest.json 編輯  {rootproject}/manifest.json 設定以下的內容 { "manifest_version": 2, ..., "content_security_policy": "script-src 'self' 'unsafe-eval' https://xxx; object-src 'self'", "content_scripts": [ ... ] } "script-src ‘self’ 這個security policy務必要設定 設定 angular.json 編輯  {root}/{angular-project}/angular.json 設定輸出專案的位置,如下 { " projects ": { " forest-admin-client ": { " architect ": { " build ": { " builder ": "@angular-devkit/build-angular:browser" , " options ": { " outputPath ": "輸出專案的位置" , 本專的 outputPath 設定是  dist/forest-admin-