Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
doxiaodong committed Sep 25, 2017
1 parent 4fa8810 commit a7bfe2b
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 78 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>ng2-simplemde</title></head><body><simplemde-app></simplemde-app><script type="text/javascript" src="./lib.e02ecc357b24d743d402.js"></script><script type="text/javascript" src="./main.e02ecc357b24d743d402.js"></script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>ng2-simplemde</title></head><body><simplemde-app></simplemde-app><script type="text/javascript" src="./lib.c301294b17eb2be23a58.js"></script><script type="text/javascript" src="./main.c301294b17eb2be23a58.js"></script></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/main.c301294b17eb2be23a58.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/main.e02ecc357b24d743d402.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/doxiaodong/ng2-simplemde"
},
"version": "1.3.0",
"version": "1.3.1",
"license": "MIT",
"main": "bundles/ng2-simplemde.umd.min.js",
"module": "lib/index.js",
Expand Down
18 changes: 18 additions & 0 deletions server/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@ import {
OnInit,
ViewEncapsulation
} from '@angular/core'
import {
FormGroup,
Validators,
FormBuilder
} from '@angular/forms'

@Component({
selector: 'simplemde-app',
encapsulation: ViewEncapsulation.None,
template: require('./app.html')
})
export class AppComponent implements OnInit {
form: FormGroup

value = '11111'

constructor(
fb: FormBuilder
) {

this.form = fb.group({
key: [
'',
Validators.required
]
})
}

ngOnInit() { }
}
3 changes: 3 additions & 0 deletions server/app/app.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
value: {{ value }}
<simplemde [(ngModel)]="value"></simplemde>
<simplemde [(ngModel)]="value" [options]="{ placeholder: '111' }"></simplemde>
<form [formGroup]="form">
<simplemde formControlName="key" [(ngModel)]="value"></simplemde>
</form>
8 changes: 8 additions & 0 deletions server/share/share.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import {
ModuleWithProviders
} from '@angular/core'
import { CommonModule } from '@angular/common'
import {
FormsModule,
ReactiveFormsModule
} from '@angular/forms'
import { SimplemdeModule } from '../../src'

@NgModule({
imports: [
FormsModule,
ReactiveFormsModule,
CommonModule,
SimplemdeModule
],
exports: [
FormsModule,
ReactiveFormsModule,
CommonModule,
SimplemdeModule
]
Expand Down
11 changes: 10 additions & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ export class Simplemde extends NgModelBase implements AfterViewInit, OnDestroy {
@Input() options: SimpleMDE.Options = {}

private simplemde: SimpleMDE
private tmpValue = null

writeValue(v: any) {
if (v !== this._innerValue) {
this._innerValue = v
if (this.value != null) {
if (this.simplemde && this.value != null) {
this.simplemde.value(this.value)
}
if (!this.simplemde) {
this.tmpValue = this.value
}
}
}

Expand All @@ -59,6 +63,11 @@ export class Simplemde extends NgModelBase implements AfterViewInit, OnDestroy {

this.simplemde = new SimpleMDE(config)

if (this.tmpValue) {
this.simplemde.value(this.tmpValue)
this.tmpValue = null
}

this.simplemde.codemirror.on('change', () => {
this.value = this.simplemde.value()
})
Expand Down

0 comments on commit a7bfe2b

Please sign in to comment.