angular-electron中如何引入Zorro元件庫
zorro框架是angular開發者十分常用的UI框架。然而,在非angular腳手架中引入zorro樣式會報錯,如下:
Your project is not using the default builders for "build". The NG-ZORRO schematics cannot add a theme to the workspace configuration if the builder has been changed.
解決方案
1.手動安裝元件
npm install ng-zorro-antd --save
2.在styles.scss檔案中新增樣式
@import "~ng-zorro-antd/ng-zorro-antd.min.css";
//如果使用less前處理器匯入@import “~ng-zorro-antd/ng-zorro-antd.less”;
3.在共享模組SharedModule中加入需要的元件
以 NzButtonModule 模組為例,先引入元件模組:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { PageNotFoundComponent } from './components/';
import { WebviewDirective } from './directives/';
import { FormsModule } from '@angular/forms';
import { NzButtonModule } from 'ng-zorro-antd/button';
@NgModule({
declarations: [PageNotFoundComponent, WebviewDirective],
imports: [
CommonModule,
TranslateModule,
FormsModule,
],
exports: [
TranslateModule,
WebviewDirective,
FormsModule,
NzButtonModule
]
})
export class SharedModule {}
*4.如果想引入全部元件,可以新建一個模組並在共享模組中匯出
Zorro元件庫,這裡命名為ng-zorro-antd-icon.module.ts
import { NgModule } from '@angular/core';
import { NzAffixModule } from 'ng-zorro-antd/affix';
import { NzAlertModule } from 'ng-zorro-antd/alert';
import { NzAnchorModule } from 'ng-zorro-antd/anchor';
import { NzAutocompleteModule } from 'ng-zorro-antd/auto-complete';
import { NzAvatarModule } from 'ng-zorro-antd/avatar';
import { NzBackTopModule } from 'ng-zorro-antd/back-top';
import { NzBadgeModule } from 'ng-zorro-antd/badge';
import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzCalendarModule } from 'ng-zorro-antd/calendar';
import { NzCardModule } from 'ng-zorro-antd/card';
import { NzCarouselModule } from 'ng-zorro-antd/carousel';
import { NzCascaderModule } from 'ng-zorro-antd/cascader';
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
import { NzCollapseModule } from 'ng-zorro-antd/collapse';
import { NzCommentModule } from 'ng-zorro-antd/comment';
import { NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation';
import { NzTransButtonModule } from 'ng-zorro-antd/core/trans-button';
import { NzWaveModule } from 'ng-zorro-antd/core/wave';
import { NzDatePickerModule } from 'ng-zorro-antd/date-picker';
import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { NzDividerModule } from 'ng-zorro-antd/divider';
import { NzDrawerModule } from 'ng-zorro-antd/drawer';
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzEmptyModule } from 'ng-zorro-antd/empty';
import { NzFormModule } from 'ng-zorro-antd/form';
import { NzGridModule } from 'ng-zorro-antd/grid';
import { NzI18nModule } from 'ng-zorro-antd/i18n';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzInputModule } from 'ng-zorro-antd/input';
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
import { NzLayoutModule } from 'ng-zorro-antd/layout';
import { NzListModule } from 'ng-zorro-antd/list';
import { NzMentionModule } from 'ng-zorro-antd/mention';
import { NzMenuModule } from 'ng-zorro-antd/menu';
import { NzMessageModule } from 'ng-zorro-antd/message';
import { NzModalModule } from 'ng-zorro-antd/modal';
import { NzNotificationModule } from 'ng-zorro-antd/notification';
import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
import { NzPaginationModule } from 'ng-zorro-antd/pagination';
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
import { NzPopoverModule } from 'ng-zorro-antd/popover';
import { NzProgressModule } from 'ng-zorro-antd/progress';
import { NzRadioModule } from 'ng-zorro-antd/radio';
import { NzRateModule } from 'ng-zorro-antd/rate';
import { NzResultModule } from 'ng-zorro-antd/result';
import { NzSelectModule } from 'ng-zorro-antd/select';
import { NzSkeletonModule } from 'ng-zorro-antd/skeleton';
import { NzSliderModule } from 'ng-zorro-antd/slider';
import { NzSpinModule } from 'ng-zorro-antd/spin';
import { NzStatisticModule } from 'ng-zorro-antd/statistic';
import { NzStepsModule } from 'ng-zorro-antd/steps';
import { NzSwitchModule } from 'ng-zorro-antd/switch';
import { NzTableModule } from 'ng-zorro-antd/table';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { NzTagModule } from 'ng-zorro-antd/tag';
import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';
import { NzTimelineModule } from 'ng-zorro-antd/timeline';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { NzTransferModule } from 'ng-zorro-antd/transfer';
import { NzTreeModule } from 'ng-zorro-antd/tree';
import { NzTreeSelectModule } from 'ng-zorro-antd/tree-select';
import { NzTypographyModule } from 'ng-zorro-antd/typography';
import { NzUploadModule } from 'ng-zorro-antd/upload';
import { NzResizableModule } from 'ng-zorro-antd/resizable';
@NgModule({
exports: [
NzAffixModule,
NzAlertModule,
NzAnchorModule,
NzAutocompleteModule,
NzAvatarModule,
NzBackTopModule,
NzBadgeModule,
NzButtonModule,
NzBreadCrumbModule,
NzCalendarModule,
NzCardModule,
NzCarouselModule,
NzCascaderModule,
NzCheckboxModule,
NzCollapseModule,
NzCommentModule,
NzDatePickerModule,
NzDescriptionsModule,
NzDividerModule,
NzDrawerModule,
NzDropDownModule,
NzEmptyModule,
NzFormModule,
NzGridModule,
NzI18nModule,
NzIconModule,
NzInputModule,
NzInputNumberModule,
NzLayoutModule,
NzListModule,
NzMentionModule,
NzMenuModule,
NzMessageModule,
NzModalModule,
NzNoAnimationModule,
NzNotificationModule,
NzPageHeaderModule,
NzPaginationModule,
NzPopconfirmModule,
NzPopoverModule,
NzProgressModule,
NzRadioModule,
NzRateModule,
NzResultModule,
NzSelectModule,
NzSkeletonModule,
NzSliderModule,
NzSpinModule,
NzStatisticModule,
NzStepsModule,
NzSwitchModule,
NzTableModule,
NzTabsModule,
NzTagModule,
NzTimePickerModule,
NzTimelineModule,
NzToolTipModule,
NzTransButtonModule,
NzTransferModule,
NzTreeModule,
NzTreeSelectModule,
NzTypographyModule,
NzUploadModule,
NzWaveModule,
NzResizableModule,
],
})
export class NgZorroAntdModule {}
zorro圖示庫(部分)這裡命名為ng-zorro-antd.module.ts,
由於圖示使用頻率不高,因此需要用到什麼引入什麼
import { IconDefinition } from '@ant-design/icons-angular';
import { NzIconModule } from 'ng-zorro-antd/icon';
import {
UserOutline,
LaptopOutline,
NotificationOutline,
} from '@ant-design/icons-angular/icons';
import { NgModule } from '@angular/core';
const icons: IconDefinition[] = [
UserOutline,
LaptopOutline,
NotificationOutline,
];
@NgModule({
imports: [NzIconModule.forRoot(icons)],
})
export class IconModule {}
共享模組share.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { PageNotFoundComponent } from './components/';
import { WebviewDirective } from './directives/';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgZorroAntdModule } from '.././ng-zorro-antd.module';
import { IconModule } from '.././ng-zorro-antd-icon.module';
@NgModule({
declarations: [PageNotFoundComponent, WebviewDirective],
imports: [
CommonModule,
TranslateModule,
FormsModule,
NgZorroAntdModule,
IconModule,
BrowserAnimationsModule,
],
exports: [
TranslateModule,
WebviewDirective,
FormsModule,
NgZorroAntdModule,
IconModule,
BrowserAnimationsModule,
]
})
export class SharedModule {}
這裡由於我的共享元件使用到了zorro元件,所以我的共享模組也引入了zorro元件。
這篇文章作為學習angualr的經歷路程,如果在這裡遇到了問題,主要是對angular的共享模組、特性模組可能不太熟悉。
》》》共享模組學習參考:Angular NgModule 作用域相關問題
》》》Zorro引入參考:Zorro快速上手
》》》案例演示angular+electron+zorro模板
相關文章
- QT creator中cmake管理專案,如何引入外部庫(引入Eigen庫為例)QT
- NG-ZORRO-MOBILE (Ant Design Mobile of Angular) 移動端UI元件庫正式釋出AngularUI元件
- Vue中元件中引入元件只渲染標籤名Vue元件
- QT5中引入GMSSL庫QT
- 如何在 Vue 元件中更好的引入一個第三方 JSVue元件JS
- Angular專案中如何引入 bootstrapAngularboot
- 致敬 React: 為 Vue 引入容器元件和展示元件ReactVue元件
- 基於Vue 2的前端如何引入評論區元件ArtalkVue前端元件
- Blazor 元件庫 BootstrapBlazor 中Editor元件介紹Blazor元件boot
- vue 引入圖示庫Vue
- 禁用 Spring Boot 中引入安全元件 spring-boot-starter-security 的方法Spring Boot元件
- react引入相同元件時互不影響React元件
- 如何快速構建React元件庫React元件
- 如何開發React UI元件庫ReactUI元件
- Maven中GeoTools的引入及Maven中央倉庫地址大全Maven
- Vue中引入jQuery兩種方式可在vue中引入jQueryVuejQuery
- vue中引入echartsVueEcharts
- 乾貨| 如何在自有App中引入小遊戲?APP遊戲
- Node 中如何引入一個模組及其細節
- 如何在css中引入自定義字型(font-face)CSS自定義字型
- 從0搭建Vue3元件庫(五): 如何使用Vite打包元件庫Vue元件Vite
- 深度解讀資料庫引入LLVM技術後如何提升效能資料庫LVM
- Qt Creator 引入第三方庫如何寫PRI檔案QT
- ①SpringCloud 實戰:引入Eureka元件,完善服務治理SpringGCCloud元件
- vue中如何引入公共樣式的的styl檔案Vue
- vue專案中如何全域性引入scss/sass檔案VueCSS
- 如何從0開始搭建 Vue 元件庫Vue元件
- Flutter開發:如何引入第三方庫並安裝使用Flutter
- 微信小程式中引用vant元件庫微信小程式元件
- golang 專案引入私有倉庫包Golang
- 找出消失的已引入的類庫
- Angular引入第三方庫Angular
- Vue 中如何正確引入第三方模組Vue
- 關於公司引入閘道器元件的提議元件
- 如何從頭到尾做一個UI元件庫UI元件
- 基於 Angular7,ng-zorro7.x 的中後臺實踐案例Angular
- NG-ZORRO(Ant Design + Angular) 1.0 版本釋出Angular
- 騰訊的cherry-markdown如何在vue專案中自定義影片播放器?【引入自定義元件版,非普通html】Vue播放器元件HTML