Movatterモバイル変換


[0]ホーム

URL:


⚠️

Security Update: Classic tokens have been revoked. Granular tokens are now limited to 90 days and require 2FA by default. Update your CI/CD workflows to avoid disruption.Learn more.

ngx-text-diff
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published
  • A simple text diffcomponent to be used with Angular and based ongoogle diff match patch library.

Dependencies

  • diff-match-patch : ^1.0.4

Required Packages

These packages will not be auto-installed and must be installed in addition to this library.

  • @angular/common >= 6.0.0
  • @angular/core >= 6.0.0
  • @angular/forms >= 6.0.0
  • @angular/cdk >= 6.0.0 (used for scrolling synchronization)

Demo

Ngx Text Diff Demo

Installation

npm i ngx-text-diff

API

module: NgxTextDiffModule
component: NgxTextDiffComponent
selector: td-ngx-text-diff

Inputs

InputTypeRequiredDescription
leftstringYesFirst text to be compared
rightstringYesSecond text to be compared
diffContentObservableOptionalDiffContent observable
formatDiffTableFormatOptional, default:SideBySidePossible values:
-SideBySide
-LineByLine
loadingbooleanOptional, default:falsePossible values:
-true: shows an loading spinner.
-false: hides the loading spinner
hideMatchingLinesbooleanOptional, default:falsePossible values:
-true: Only shows lines with differences.
-false: shows all lines
showToolbarbooleanOptional, default:truePossible values:
-true: shows the toolbar.
-false: hides the format toolbar
showBtnToolbarbooleanOptional, default:truePossible values:
-true: shows the format toolbar.
-false: hides the format toolbar
outerContainerClassanyOptionalngClass object for the outer div
outerContainerStyleanyOptionalngStyle object for the outer style
toolbarClassanyOptionalngClass object for the toolbar div
toolbarStyleanyOptionalngStyle object for the toolbar style
compareRowsClassanyOptionalngClass object for the div surrounding the table rows
compareRowsStyleanyOptionalngStyle object for the div surrounding the table rows
synchronizeScrollingbooleanOptional, default:truePossible values:
-true: Scrolls both tables together.
-false: Scrolls individually

Output

InputTypeRequiredDescription
compareResultsDiffResultsOptionalEvent fired when comparison is executed

Custom Objects

exportinterfaceDiffContent{leftContent:string;rightContent:string;}exporttypeDiffTableFormat='SideBySide'|'LineByLine';exportinterfaceDiffResults{hasDiff:boolean;diffsCount:number;rowsWithDiff:{leftLineNumber?:number;rightLineNumber?:number;numDiffs:number;}[];}

Usage

  1. Register theNgxTextDiffModule in a module, for example app module.
import{BrowserModule}from'@angular/platform-browser';import{NgModule}from'@angular/core';import{ScrollDispatchModule}from'@angular/cdk/scrolling';import{AppComponent}from'./app.component';import{NgxTextDiffModule}from'ngx-text-diff';@NgModule({declarations:[AppComponent],imports:[BrowserModule,ScrollDispatchModule,NgxTextDiffModule],providers:[],bootstrap:[AppComponent]})exportclassAppModule{}
import{Component,OnInit}from'@angular/core';import{DiffContent,DiffResults}from'ngx-text-diff/lib/ngx-text-diff.model';@Component({selector:'app-home',templateUrl:'./home.component.html',styleUrls:[]})exportclassHomeComponentimplementsOnInit{left=`some text to\nbe compared!`right=`A changed\n version \n of the text to\nbe compared!`constructor(){}ngOnInit(){}onCompareResults(diffResults:DiffResults){console.log('diffResults',diffResults);}}
<td-ngx-text-diff[left]="left"[right]="right"(compareResults)="onCompareResults($event)">

Build the NgxTextDiff module

Runng build ngx-text-diff to build the library. The build artifacts will be stored in thedist/ngx-text-diff directory.

Credits

This project is based ongoogle diff match patch.

Package Sidebar

Install

npm i ngx-text-diff

Weekly Downloads

4,530

Version

0.6.0

License

MIT

Unpacked Size

617 kB

Total Files

46

Last publish

Collaborators

  • abenassi87

[8]ページ先頭

©2009-2026 Movatter.jp