[英]Unable to add SharePoint list item with attachment from Angular to ASP.NET Core Web API using NgModel
I have added the SharePoint list item with an attachment from Angular to ASP.NET Core Web API.我已将带有附件的 SharePoint 列表项从 Angular 添加到 ASP.NET Core Web API。 I have used FormControl in the Angular application.我在 Angular 应用程序中使用了 FormControl。
I have referred below link, How to Upload File from Angular to ASP.NET Core Web API我参考了下面的链接, 如何将文件从 Angular 上传到 ASP.NET Core Web API
Now, I need to perform the same using NgModel instead of FormControl in the Angular application.现在,我需要在 Angular 应用程序中使用 NgModel 而不是 FormControl 来执行相同的操作。
Can anyone help me with the same?任何人都可以帮助我吗?
Thanks谢谢
i use example of this link, How to Upload File from Angular to ASP.NET Core Web API .我使用此链接的示例, 如何将文件从 Angular 上传到 ASP.NET Core Web API 。 i think must be like this :我想一定是这样的:
html html
<form (ngSubmit)="onSubmit()">
<div>
<label for="Name">
Blog Name
</label>
<input type="text" name="Name" [(ngModel)]="Name">
</div>
<div>
<label for="TileImage">
Tile Image
</label>
<input type="file" name="TileImage" [(ngModel)]="TileImage">
</div>
<button type="submit">Create Blog</button>
</form>
typescript打字稿
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { BlogService } from '../blog-services/blog.service';
@Component({
selector: 'app-new-blog',
templateUrl: './new-blog.component.html',
styleUrls: ['./new-blog.component.css']
})
export class NewBlogComponent implements OnInit {
public Name = '';
public TileImage= '';
constructor(private blogService: BlogService) { }
ngOnInit() {}
onSubmit() {
this.blogService.postBlog({Name:this.Name,TileImage:this.TileImage});
this.Name='';
this.TileImage='';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.