angular自定义双向绑定表单组件

angular的ControlValueAccessor是一个连接表单模型和视图DOM的抽象类接口 .org-center { margin-left: auto; margin-right: auto; text-align: center; } 使自定义表单组件像原生input一样映射到form表单模型中, 拥有自定义表单组件的form也能使用响应式表单. (也就是使自定义表单组件拥有formControlName属性和ngModel接口.) 毕竟响应式表单才是angular的利器. ControlValueAccessor export interface ControlValueAccessor { writeValue(obj: any): void; registerOnChange(fn: any): void; registerOnTouched(fn: any): void; setDisabledState?(isDisabled: boolean): void; } writeValue(obj: any): 该方法是接收模版中的ngModel. writeValue(value: any): void { this._renderer.setProperty(this._elementRef.nativeElement, 'value', value); } registerOnChange(fn: any): void: 该方法是组件接收到 change 事件的回调, 可以用来通知外部达成双向绑定, 即ngModelChange. registerOnChange(fn: (_: any) => void): void { this._onChange = fn; } registerOnTouched(fn: any): 接收到 touched 事件的回调. registerOnTouched(fn: any): void { this....

July 8, 2019 · 2 min · zakudriver

vimrc

" .vimrc " Configuration file for vim set modelines=0 " Don't write backup file if vim is being called by "crontab -e" " au BufWrite /private/tmp/crontab.* set nowritebackup nobackup " Don't write backup file if vim is being called by "chpass" " au BufWrite /private/etc/pw.* set nowritebackup nobackup set nobackup set nowritebackup let skip_defaults_vim=1 " <leader> let g:mapleader="," " 去掉有关vi一致性模式,避免以前版本的bug和局限 set nocompatible " 设置退格键可用 set backspace=2 " utf-8 set encoding=UTF-8 " 主题 " set background=dark " colorscheme dracula " 函数方法名加粗 let g:enable_bold_font = 1 " 注释斜体 let g:enable_italic_font = 1 " 透明背景 let g:hybrid_transparent_background = 1 " airline_theme let g:airline_theme = "hybrid" " 行号 set nu!...

June 4, 2019 · 5 min · zakudriver

一个包含 nil 指针的接口不是 nil 接口

golang 接口值: 一个包含 nil 指针的接口不是 nil 接口. 一个不包含任何值的 nil 接口值和一个刚好包含 nil 指针的接口值是不同的. 接口值由两个部分组成: 一个具体的类型 那个类型的值 它们被称为接口的动态类型和动态值. type value x x 接口的零值是指动态类型为nil, 动态值也为nil. type value nil nil 这样的接口才能满足 接口值 == nil. var a interface{} fmt.Println(a == nil) // true 一个不包含任何值的 nil 接口值: interface 类型变量的动态类型和动态值都为 nil. 比如 nil, 或者:...

March 25, 2019 · 1 min · zakudriver

vscode

{ // editor "editor.fontSize": 14, "editor.snippetSuggestions": "top", "editor.formatOnSave": true, "explorer.confirmDragAndDrop": true, "explorer.confirmDelete": false, "editor.detectIndentation": false, "files.autoSave": "off", // "editor.fontFamily": "'FuraCode', Menlo, Monaco, 'Courier New', monospace", "editor.fontLigatures": true, "workbench.iconTheme": "material-icon-theme", "workbench.colorTheme": "Nebula", // prettier "prettier.printWidth": 120, "editor.tabSize": 2, "prettier.singleQuote": false, "prettier.semi": true, // typescript "typescript.updateImportsOnFileMove.enabled": "always", // emmet "emmet.includeLanguages": { "javascript": "javascriptreact", "typescript": "typescriptreact" }, "emmet.triggerExpansionOnTab": true, // 装饰器 "javascript.implicitProjectConfig.experimentalDecorators": true, // stylus "stylusSupremacy.insertColons": false, // 是否插入冒号 "stylusSupremacy.insertSemicolons": false, // 是否插入分好 "stylusSupremacy....

March 2, 2019 · 2 min · zakudriver