Forms 禁用DOM字段表单后的角度刷新页面
我单击“购买”单选按钮,图像上载字段将被删除,但当我单击“提交”时,页面将刷新。当我不影响DOM时,它正常工作 请给我解释一下发生了什么事 这是我的密码Forms 禁用DOM字段表单后的角度刷新页面,forms,angular,Forms,Angular,我单击“购买”单选按钮,图像上载字段将被删除,但当我单击“提交”时,页面将刷新。当我不影响DOM时,它正常工作 请给我解释一下发生了什么事 这是我的密码 onSubmitPost() { this.progress = true; const fileList: FileList = this.event.target.files; if (fileList.length > 0) { const fileListLength = fileList.le
onSubmitPost() {
this.progress = true;
const fileList: FileList = this.event.target.files;
if (fileList.length > 0) {
const fileListLength = fileList.length;
const formData: FormData = new FormData();
formData.append('title', this.title);
formData.append('telephone', this.telephone);
formData.append('description', this.description);
formData.append('city', this.city);
if (this.isSell === true) {
for (let x = 0; x < fileListLength; x++) {
formData.append('thumbnail', fileList[x]);
}
}
const headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Authorization', 'clientId 7702919f7e72965');
this.http
.post('http://localhost:3000/api/post', formData, {
headers: headers
})
.map(res => res.json())
.subscribe(
data => {
this.Notificationervice.success('Success');
this.progress = false;
},
error => this.Notificationervice.error('Something wrong')
);
}
}
}
onSubmitPost(){
这是真的;
const fileList:fileList=this.event.target.files;
如果(fileList.length>0){
const fileListLength=fileList.length;
const formData:formData=new formData();
formData.append('title',this.title);
formData.append('telephone',this.telephone);
formData.append('description',this.description);
formData.append('city',this.city);
if(this.isSell==true){
for(设x=0;xres.json())
.订阅(
数据=>{
这个.notificationservice.success('success');
这个。进步=错误;
},
error=>this.notificationservice.error('Something error')
);
}
}
}
HTML代码
<div id="new-post" class="modal" materialize="modal">
<div class="modal-content">
<div class="row">
<form class="col s12" (submit)="onSubmitPost()" enctype="multipart/form-data">
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">web</i>
<input id="icon_prefix" type="text" class="validate" name="title" [(ngModel)]="title">
<label for="icon_prefix">Title</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">phone</i>
<input id="icon_telephone" type="tel" class="validate" name="telephone" [(ngModel)]="telephone">
<label for="icon_telephone">Telephone</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">mode_edit</i>
<textarea id="icon_prefix2" class="materialize-textarea" [(ngModel)]="description" name="description"></textarea>
<label for="icon_prefix2">Description</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">location_on</i>
<input type="text" id="autocomplete-input" class="autocomplete" materialize="autocomplete" [materializeParams]="[{'data': {'houston': null, 'Cali': null}}]"
[(ngModel)]="city" name="city">
<label for="autocomplete-input">City</label>
</div>
</div>
<div class="row">
<div class="col s6">
<p>
<input name="isSell" type="radio" id="buy" (change)="isSell = !isSell" [checked]="!isSell" />
<label for="buy">Buy</label>
</p>
</div>
<div class="col s6">
<p>
<input name="isSell" type="radio" id="sell" (change)="isSell = !isSell" [checked]="isSell" />
<label for="sell">Sell</label>
</p>
</div>
</div>
<div class="file-field input-field" *ngIf="isSell">
<div class="btn">
<span>Images</span>
<input type="file" multiple accept='image/*' name="post" (change)="onChange($event)">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload one or more files">
</div>
</div>
<div class="modal-footer">
<input type="submit" class="modal-action modal-close waves-effect waves-green btn-flat" value="Submit">
</div>
</form>
</div>
</div>
</div>
网状物
标题
电话
电话
编辑模式
描述
地点
城市
购买
卖
图像
您只需复制粘贴代码即可,这样更具可读性和可搜索性哦!关于那件事