input binding not working well
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
<div class="canvas" appCanvas (emitConfig)="updateCanvasConfig($event)" [param]="canvasParam"></div>
|
<div appCanvas class="canvas" (emitConfig)="updateCanvasConfig($event)" [param]="canvasParam"></div>
|
||||||
|
|
||||||
<ul *ngIf="canvasConfig">
|
<ul *ngIf="canvasConfig">
|
||||||
<li><b>Static Configuration</b></li>
|
<li><b>Static Configuration</b></li>
|
||||||
<li><pre>{{canvasConfig | json}}</pre></li>
|
<li><pre>{{canvasConfig | json}}</pre></li>
|
||||||
<li><b>Changeable Parameters</b></li>
|
<li><b>Changeable Parameters</b></li>
|
||||||
<li><pre>{{canvasParam | json}}</pre></li>
|
<li><pre>{{canvasParam | json}}</pre></li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<div><input type="number" [(ngModel)]="canvasParam.points"></div>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
import { Param } from './models/param.model';
|
import { Param } from './models/param.model';
|
||||||
import { Config } from './models/config.model';
|
import { Config } from './models/config.model';
|
||||||
@@ -11,6 +12,7 @@ import { Config } from './models/config.model';
|
|||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
public canvasConfig: Config;
|
public canvasConfig: Config;
|
||||||
public canvasParam: Param;
|
public canvasParam: Param;
|
||||||
|
public test: number;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.canvasParam = {
|
this.canvasParam = {
|
||||||
@@ -18,8 +20,9 @@ export class AppComponent {
|
|||||||
start: '#cc0045',
|
start: '#cc0045',
|
||||||
end: '#0067cc'
|
end: '#0067cc'
|
||||||
},
|
},
|
||||||
points: 5
|
points: 3
|
||||||
};
|
};
|
||||||
|
this.test = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateCanvasConfig(config): void {
|
public updateCanvasConfig(config): void {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { CanvasDirective } from './canvas/canvas.directive';
|
import { CanvasDirective } from './canvas/canvas.directive';
|
||||||
@@ -10,7 +11,8 @@ import { CanvasDirective } from './canvas/canvas.directive';
|
|||||||
CanvasDirective
|
CanvasDirective
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule
|
BrowserModule,
|
||||||
|
FormsModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { CanvasDirective } from './canvas.directive';
|
|
||||||
|
|
||||||
describe('CanvasDirective', () => {
|
|
||||||
it('should create an instance', () => {
|
|
||||||
const directive = new CanvasDirective();
|
|
||||||
expect(directive).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Directive, ElementRef, Renderer, AfterViewInit, HostListener, Output, EventEmitter, OnInit, Input } from '@angular/core';
|
import { ElementRef, HostListener, Output, EventEmitter, OnInit, Input, OnChanges, SimpleChanges, Directive } from '@angular/core';
|
||||||
import * as Selection from 'd3-selection';
|
import * as Selection from 'd3-selection';
|
||||||
import * as Shape from 'd3-shape';
|
import * as Shape from 'd3-shape';
|
||||||
import * as Random from 'd3-random';
|
import * as Random from 'd3-random';
|
||||||
@@ -11,7 +11,7 @@ import { Param } from './../models/param.model';
|
|||||||
@Directive({
|
@Directive({
|
||||||
selector: '[appCanvas]'
|
selector: '[appCanvas]'
|
||||||
})
|
})
|
||||||
export class CanvasDirective implements OnInit {
|
export class CanvasDirective implements OnInit, OnChanges {
|
||||||
private canvas: any;
|
private canvas: any;
|
||||||
private defs: any;
|
private defs: any;
|
||||||
private gradient: any;
|
private gradient: any;
|
||||||
@@ -20,9 +20,11 @@ export class CanvasDirective implements OnInit {
|
|||||||
private drag: Point;
|
private drag: Point;
|
||||||
public config: Config;
|
public config: Config;
|
||||||
|
|
||||||
@Input() param: Param;
|
@Input()
|
||||||
|
private param: Param;
|
||||||
|
|
||||||
@Output() emitConfig: EventEmitter<Config>;
|
@Output()
|
||||||
|
private emitConfig: EventEmitter<Config>;
|
||||||
|
|
||||||
@HostListener('window:resize', ['$event'])
|
@HostListener('window:resize', ['$event'])
|
||||||
private onResize(event) {
|
private onResize(event) {
|
||||||
@@ -30,13 +32,16 @@ export class CanvasDirective implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private el: ElementRef,
|
private el: ElementRef
|
||||||
private renderer: Renderer
|
|
||||||
) {
|
) {
|
||||||
this.canvas = el.nativeElement;
|
this.canvas = el.nativeElement;
|
||||||
this.emitConfig = new EventEmitter();
|
this.emitConfig = new EventEmitter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
console.log(changes.param);
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user