- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 首頁
- Ngx-Bootstrap - 概述
- Ngx-Bootstrap - 環境設定
- Ngx-Bootstrap - 手風琴
- Ngx-Bootstrap - 警報
- Ngx-Bootstrap - 按鈕
- Ngx-Bootstrap - 走馬燈
- Ngx-Bootstrap - 摺疊
- Ngx-Bootstrap - 日期選擇器
- Ngx-Bootstrap - 下拉選單
- Ngx-Bootstrap - 模態框
- Ngx-Bootstrap - 分頁
- Ngx-Bootstrap - 氣泡提示
- Ngx-Bootstrap - 進度條
- Ngx-Bootstrap - 評分
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 標籤頁
- Ngx-Bootstrap - 時間選擇器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - 自動完成
- Ngx-Bootstrap 有用資源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用資源
- Ngx-Bootstrap - 討論
Ngx-Bootstrap - 可排序
ngx-bootstrap 可排序元件提供了一個可配置的可排序元件,支援拖放。
SortableComponent
選擇器
bs-sortable
輸入
fieldName − 字串,如果輸入陣列包含物件,則為欄位名稱。
itemActiveClass − 字串,活動專案的類名。
itemActiveStyle − { [key: string]: string; },活動專案的樣式物件。
itemClass − 字串,專案的類名
itemStyle − 字串,專案的類名
itemTemplate − TemplateRef<any>,用於指定自定義專案模板。模板變數:item 和 index;
placeholderClass − 字串,佔位符的類名
placeholderItem − 字串,如果集合為空,則顯示的佔位符專案
placeholderStyle − 字串,佔位符的樣式物件
wrapperClass − 字串,專案包裝器的類名
wrapperStyle − { [key: string]: string; },專案包裝器的樣式物件
輸出
onChange − 在陣列更改(重新排序、插入、刪除)時觸發,與 ngModelChange 相同。返回新的專案集合作為有效負載。
示例
由於我們將使用可排序元件,因此我們必須更新 ngx-bootstrap 評分 章節中使用的 app.module.ts,以使用SortableModule 和DraggableItemService。
更新 app.module.ts 以使用 SortableModule 和 DraggableItemService。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { AlertModule,AlertConfig } from 'ngx-bootstrap/alert';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule, BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule,BsDropdownConfig } from 'ngx-bootstrap/dropdown';
import { PaginationModule,PaginationConfig } from 'ngx-bootstrap/pagination';
import { PopoverModule, PopoverConfig } from 'ngx-bootstrap/popover';
import { ProgressbarModule,ProgressbarConfig } from 'ngx-bootstrap/progressbar';
import { RatingModule, RatingConfig } from 'ngx-bootstrap/rating';
import { SortableModule, DraggableItemService } from 'ngx-bootstrap/sortable';
@NgModule({
declarations: [
AppComponent,
TestComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AccordionModule,
AlertModule,
ButtonsModule,
FormsModule,
CarouselModule,
CollapseModule,
BsDatepickerModule.forRoot(),
BsDropdownModule,
ModalModule,
PaginationModule,
PopoverModule,
ProgressbarModule,
RatingModule,
SortableModule
],
providers: [AlertConfig,
BsDatepickerConfig,
BsDropdownConfig,
BsModalService,
PaginationConfig,
ProgressbarConfig,
RatingConfig,
DraggableItemService],
bootstrap: [AppComponent]
})
export class AppModule { }
更新 styles.css 以使用可排序元件的樣式。
Styles.css
.sortableItem {
padding: 6px 12px;
margin-bottom: 4px;
font-size: 14px;
line-height: 1.4em;
text-align: center;
cursor: grab;
border: 1px solid transparent;
border-radius: 4px;
border-color: #adadad;
}
.sortableItemActive {
background-color: #e6e6e6;
box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
}
.sortableWrapper {
min-height: 150px;
}
更新 test.component.html 以使用可排序元件。
test.component.html
<bs-sortable [(ngModel)]="items" fieldName="name" itemClass="sortableItem" itemActiveClass="sortableItemActive" wrapperClass="sortableWrapper"> </bs-sortable>
更新 test.component.ts 以對應變數和方法。
test.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
items = [
{
id: 1,
name: 'Apple'
},
{
id: 2,
name: 'Orange'
},
{
id: 3,
name: 'Mango'
}
];
constructor() {}
ngOnInit(): void {
}
}
構建和服務
執行以下命令以啟動 Angular 伺服器。
ng serve
伺服器啟動並執行後,開啟 https://:4200。