加入网站图标预览和友链页链接自动补写

This commit is contained in:
禾几海
2020-08-07 21:29:30 +08:00
parent 953fba5b17
commit 5454a747a7
2 changed files with 15 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ export class LinkComponent implements OnInit {
loading: boolean = false;
applyFormGroup: FormGroup;
colors: Color[];
private lastUrl: string = '';
ngOnInit() {
@@ -50,6 +51,13 @@ export class LinkComponent implements OnInit {
name: [null, [Validators.required, Validators.maxLength(255)]],
url: [null, [Validators.required, Validators.pattern(/^([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]]
});
this.applyFormGroup.controls.url.valueChanges.subscribe({
next: data => {
const linkUrlData: string = this.applyFormGroup.value.linkUrl || '';
this.applyFormGroup.patchValue({linkUrl: linkUrlData.replace(this.lastUrl, data)});
this.lastUrl = data;
},
})
}
apply() {