angular - Angular 6形式,将对象提取到输入中
问题描述
有人可以帮我将带有 data.name 的对象提取到输入中吗 这是带有输入的站点表单的图片
这是组件的html代码
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title">Edit Movie</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form #editMovieForm="ngForm" (ngSubmit)="onSave(editMovieForm)">
<div class="form-group">
<label for="runTime">Run Time</label>
<input
type="text"
name="runTime"
id="runTime"
class="form-control"
[(ngModel)]="movie.runtime"
>
</div>
<div class="form-group">
<label for="genre">Genre</label>
<input
type="text"
name="genre"
id="genre"
class="form-control"
[(ngModel)]="movie.genres"
value=""
>
</div>
<div class="form-group">
<label for="cast">Cast</label>
<input
type="text"
name="cast"
id="cast"
class="form-control"
[(ngModel)]="movie.cast"
>
</div>
<input type="submit" class="btn btn-success" value="Save">
<button
type="button"
class="btn btn-danger float-right"
(click)="onDelete()"
><i class="far fa-trash-alt"></i> Remove</button>
</form>
</div>
</ng-template>
<button class="btn btn-light mb-2 mr-2" (click)="openBackDropCustomClass(content)">Edit Movie</button>
这是一个组件
export class EditMovieModalComponent implements OnInit {
closeResult: string;
movie: any = new Object();
id: number;
constructor(
private modalService: NgbModal,
private movieService: MovieRequestService,
private flashMessage: FlashMessagesService,
private http: HttpClient,
private router: Router,
private route: ActivatedRoute
) {
this.getMovieDetails();
}
openBackDropCustomClass(content) {
this.modalService.open(content, {backdropClass: 'light-blue-backdrop'});
}
ngOnInit() {
}
getMovieDetails () {
// Get Id from URL
this.id = this.route.snapshot.params['id'];
this.movieService.getMovieDetails(this.id).subscribe(response => this.movie = response.data.movie);
}
onDelete () {
if (confirm('Are you sure ???')) {
this.movieService.deleteMovie(this.movie);
this.flashMessage.show('Movie Removed Succes');
}
}
onSave () {}
}
我无法获取 cast.name 的数据,因为它是一个对象,我该怎么做?以及如何将编辑电影保存到虚拟 dom 或有角度的东西?
解决方案
角度响应将作为 Observables 出现,你必须给它一个结构来正确读取数据,我认为你没有为 Observable 定义任何结构(接口或类),所以在这种情况下,我认为 map 函数会解决你的问题。例如:
getMovieDetails() {
return this.http.get('your URL')
.map(res => res);
}
我希望这可以解决您的问题,如果没有,请在您进行后端调用的地方发布代码。
您可以参考此链接以了解 Angular HTTP 调用和 Observables:
推荐阅读
- css - 从@keyframe 切换到过渡动画不起作用
- r - ESRI 'Slice' 工具的 R 版本?
- python - Python 测试:如何在测试范围之外进行模拟?
- excel - 如何从 Excel 插件函数返回多个结果?
- django - 是否可以同时验证默认用户模型和自定义用户模型?
- java - 关于java正则表达式
- c - 从用户那里获取#define 值
- typescript - 带有打字稿的 Apollo 网关不会在上下文中接受用户 ID
- angular - angular ng2-file-upload 获取上传的文件块
- ios - 如何使用 Swift 为 UICollectionView 创建动态宽度和静态高度