Closed sagarrajak closed 5 years ago
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { CanvasWhiteboardModule } from 'ng2-canvas-whiteboard';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CanvasWhiteboardModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { CanvasWhiteboardComponent, CanvasWhiteboardOptions } from 'ng2-canvas-whiteboard';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
viewProviders: [CanvasWhiteboardComponent],
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
public canvasOptions: CanvasWhiteboardOptions;
ngOnInit() {
this.canvasOptions = {
drawButtonEnabled: true,
drawButtonClass: "drawButtonClass",
drawButtonText: "Draw",
clearButtonEnabled: true,
clearButtonClass: "clearButtonClass",
clearButtonText: "Clear",
undoButtonText: "Undo",
undoButtonEnabled: true,
redoButtonText: "Redo",
redoButtonEnabled: true,
colorPickerEnabled: true,
saveDataButtonEnabled: true,
saveDataButtonText: "Save",
lineWidth: 5,
strokeColor: "rgb(0,0,0)",
shouldDownloadDrawing: true
};
}
onCanvasUndo() {
console.log(`Undo was called`);
}
onCanvasRedo() {
console.log('redo was called');
}
}
app.component.html
<canvas-whiteboard #canvasWhiteboard
[options]="canvasOptions"
(onBatchUpdate)="onCanvasDraw($event)"
(onClear)="onCanvasClear()"
(onUndo)="onCanvasUndo($event)"
(onRedo)="onCanvasRedo($event)">
</canvas-whiteboard>
Hello, could you please specify what the error is, on first sight, I can see that the methods onCanvasDraw($event)
and onCanvasClear()
are not implemented in the code. But that should only fail on AOT compilation (ng serve --prod
or ng build --prod
) or if you actually draw or try to clear so the method will not be found.
as a second precaution, can you try adding a <div>
wrapper with a fixed height over the canvas so maybe the problem is that the canvas cannot predict the total size of the parent. Try with a hardcoded height like
<div style="height: 400px; border: 1px solid black">
<canvas-whiteboard #canvasWhiteboard
[options]="canvasOptions"
(onBatchUpdate)="onCanvasDraw($event)"
(onClear)="onCanvasClear()"
(onUndo)="onCanvasUndo($event)"
(onRedo)="onCanvasRedo($event)">
</canvas-whiteboard>
</div>
Will close for inactivity, please reopen if this issue still happens.
package.json