I have added the SharePoint list item with an attachment from Angular to ASP.NET Core Web API. I have used FormControl in the Angular application.
I have referred below link, How to Upload File from Angular to ASP.NET Core Web API
Now, I need to perform the same using NgModel instead of FormControl in the Angular application.
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 . i think must be like this :
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='';
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.