欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ng-alain的sf如何自定義部件的流程

 更新時間:2020年06月12日 10:50:24   作者:蝸牛狂奔  
這篇文章主要介紹了ng-alain的sf如何自定義部件,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、背景

最近使用ng-alain做前端,sf的部件很豐富,但是做起來之后就會發(fā)現(xiàn),多多少少會有一些不符合需求的東西,比如:

這是一個string的部件,后邊跟上一個單位看著很不錯,但是我們通常在使用number時會更需要這個單位,然而官方的部件并沒有
再比如:

我想做一個編輯框,要求內(nèi)容不可編輯,并且該內(nèi)容要從別的列表進行選擇,下拉選擇可以滿足需求,但是如果內(nèi)容太多,有時就不方便使用下拉框了,那么這時候我們就需要自定義

二、自定義ng-alain部件的流程

1、組件的整體結(jié)構(gòu)

2、首先,組件click-input.component.html,自定義組件要包在sf-item-wrap特殊標簽里面

<sf-item-wrap [id]="id" [schema]="schema" [ui]="ui" [showError]="showError" [error]="error" [showTitle]="schema.title">
 <!-- 開始自定義控件區(qū)域 -->
 <div nz-row>
  <div nz-col nzSpan="16"><input type="text" [placeholder]="placeholder" nz-input [(ngModel)]="content" [disabled]="inputDisable" (ngModelChange)="onChange()"></div>
  <div nz-col nzSpan="2" nzPush="2"></div>
  <div nz-col nzSpan="6"><button nz-button type="button" nzType="primary" (click)="test()" >{{btnTitle}}</button></div>
 </div>
 <!-- 結(jié)束自定義控件區(qū)域 -->
</sf-item-wrap>

3、寫組件click-input.component,繼承ControlWidget

import {Component, OnInit} from '@angular/core';
import { ControlWidget } from '@delon/form';

@Component({
 selector: 'app-product-widget-click-input',
 templateUrl: './click-input.component.html',
})
export class ClickInputComponent extends ControlWidget implements OnInit {

 /* 用于注冊小部件 KEY 值 */
 static readonly KEY = 'click-input';

 // 價格區(qū)間
 content: any;
 // to: any;

 placeholder: string;  // 使用的時候用來綁定 ui: {placeholder: '請選擇業(yè)務(wù)系統(tǒng)' } 
 inputDisable: boolean; // 使用的時候用來綁定 ui: {inputDisable: true,  // input是否可用}
 btnTitle: string; // 使用的時候用來綁定 ui: {btnTitle: '選擇數(shù)據(jù)',}  按鈕名稱

 ngOnInit(): void {
  this.placeholder = this.ui.placeholder || '請輸入'; // 使用的時候用來綁定 ui: {placeholder: '請選擇業(yè)務(wù)系統(tǒng)' } 
  this.inputDisable = this.ui.inputDisable || false; // 使用的時候用來綁定 ui: {inputDisable: true,  // input是否可用}
  this.btnTitle = this.ui.btnTitle || '按鈕'; // 使用的時候用來綁定 ui: {btnTitle: '選擇數(shù)據(jù)',}
 }

 getData = () => {
  return this.content;
 }

 onChange() {
  const v = this.getData();
  this.setValue(v);
 }

 // reset 可以更好的解決表單重置過程中所需要的新數(shù)據(jù)問題
 reset(value: any) {
  if (value) {
   console.log(value);
   const content = value;
   this.content = content;
   // this.to = to;
   this.setValue(value);
  }

 }

 test(value?: string){
  if (this.ui.click) {
   this.ui.click(value);  // 可以在組件里直接調(diào)用使用ui的配置那里的方法 ui: {click: (value) => this.test(value),}
  }
 }

}

4、在shared.module.ts中注冊部件

涉及到項目內(nèi)容,以下只展示注冊部件的住要內(nèi)容

// 自定義 小部件
const WIDGETS = [
 RangeInputComponent,
 ClickInputComponent
];

@NgModule({
 declarations: [
  // your components
  ...COMPONENTS,
  ...DIRECTIVES,
  ...WIDGETS
 ],
})

export class SharedModule {
 constructor(widgetRegistry: WidgetRegistry) {
  // 注冊 自定義的 widget
  for (const widget of WIDGETS){
   widgetRegistry.register(widget.KEY /* 'range-input' */, widget);
  }
 }
}

5、使用自定義部件

channel-select.component.html

<sf [schema]="schema" (formSubmit)="submit($event)">
</sf>

channel-select.component.ts

schema: SFSchema = {
  properties: {
   btn: { type: 'string', title: '編輯框+按鈕',
    default: '1234', // 設(shè)默認值
    ui: {
     widget: 'click-input',
     placeholder: '請選擇業(yè)務(wù)系統(tǒng)',
     // inputDisable: true,  // input是否可用
     btnTitle: '選擇數(shù)據(jù)',
     click: (value) => this.test(value),
    }
   },
  }
 };

總結(jié)

到此這篇關(guān)于ng-alain的sf如何自定義部件的文章就介紹到這了,更多相關(guān)ng-alain的sf如何自定義部件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • AngularJS實現(xiàn)tab選項卡的方法詳解

    AngularJS實現(xiàn)tab選項卡的方法詳解

    這篇文章主要介紹了AngularJS實現(xiàn)tab選項卡的方法,結(jié)合實例形式較為詳細的分析了AngularJS實現(xiàn)tab選項卡的原理、實現(xiàn)技巧與相關(guān)注意事項,需要的朋友可以參考下
    2017-07-07
  • 淺談Angular單元測試總結(jié)

    淺談Angular單元測試總結(jié)

    這篇文章主要介紹了淺談Angular單元測試總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • 使用AngularJS2中的指令實現(xiàn)按鈕的切換效果

    使用AngularJS2中的指令實現(xiàn)按鈕的切換效果

    這篇文章主要介紹了使用AngularJS2中的指令實現(xiàn)按鈕的切換效果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-03-03
  • AngularJS中的緩存使用

    AngularJS中的緩存使用

    一個緩存就是一個組件,它可以透明地儲存數(shù)據(jù),以便以后可以更快地服務(wù)于請求。這篇文章主要介紹了AngularJS中的緩存使用,有興趣的可以了解一下。
    2017-01-01
  • AngularJS 依賴注入詳解及示例代碼

    AngularJS 依賴注入詳解及示例代碼

    本文主要介紹AngularJS 依賴注入的知識,這里整理了相關(guān)的基礎(chǔ)知識,并附示例代碼和實現(xiàn)效果圖,有興趣的小伙伴可以參考下
    2016-08-08
  • Angular4 中內(nèi)置指令的基本用法

    Angular4 中內(nèi)置指令的基本用法

    不得不說指令是ng最為強大的功能之一,好吧,也可以去掉之一,是最強大的功能。下面這篇文章主要給大家介紹了關(guān)于Angular4中內(nèi)置指令的基本用法,文中通過示例代碼介紹的非常詳細,需要的朋友們下面來一起看看吧。
    2017-07-07
  • AngularJS實現(xiàn)的JSONP跨域訪問數(shù)據(jù)傳輸功能詳解

    AngularJS實現(xiàn)的JSONP跨域訪問數(shù)據(jù)傳輸功能詳解

    這篇文章主要介紹了AngularJS實現(xiàn)的JSONP跨域訪問數(shù)據(jù)傳輸功能,較為詳細的分析了JSONP的概念、功能并結(jié)合實例形式給出了AngularJS使用JSONP進行跨域訪問數(shù)據(jù)傳輸?shù)南嚓P(guān)技巧,需要的朋友可以參考下
    2017-07-07
  • div實現(xiàn)自適應(yīng)高度的textarea實現(xiàn)angular雙向綁定

    div實現(xiàn)自適應(yīng)高度的textarea實現(xiàn)angular雙向綁定

    本文主要介紹了div實現(xiàn)自適應(yīng)高度的textarea,實現(xiàn)angular雙向綁定的方法。具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • AnjularJS中$scope和$rootScope的區(qū)別小結(jié)

    AnjularJS中$scope和$rootScope的區(qū)別小結(jié)

    這篇文章給大家整理了關(guān)于AnjularJS中$scope和$rootScope的區(qū)別,文中運用實例代碼介紹的很詳細,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-09-09
  • AngularJS表達式講解及示例代碼

    AngularJS表達式講解及示例代碼

    本文主要講解AngularJS表達式,這里整理了相關(guān)資料和提供示例代碼以及實現(xiàn)效果圖,有需要的小伙伴可以參考下
    2016-08-08

最新評論