【发布时间】:2022-01-24 06:26:44
【问题描述】:
所以,我现在正在学习 Angular,并尝试做一个 CRUD 应用程序。几乎一切正常,除了尝试使用 ID 获取数据时,我可以访问
component.ts
文件中的所有数据,但同样不会呈现到 html 文件中。这是我尝试过的:-
edit-to.component.ts
export class EditTodoComponent implements OnInit {
private tid: number = 0;
public Todo:TodoModel= null ;
public desc:string='';
public title:string='';
public id:number;
constructor(private route: ActivatedRoute, private http:HttpClient) { }
ngOnInit(): void {
this.route.paramMap.subscribe(all_params =>{
this.tid = parseInt(all_params.get('id'))
//console.log( all_params.get('id'))
//console.log( this.tid );
});
this.getTodoFromId(this.tid)
}
getTodoFromId(id){
//console.log("id="+id)
this.http.get<{data: any}>('http://localhost:3000/api/todos/get_todo_from_id/'+id).subscribe((data) =>{
console.log("response in angular= \n");
this.Todo = data[0]
console.log(this.Todo.todo_title) //-> This one works
}
editOnSubmit(form:NgForm){
//something here
}
edit-todo.component.html
分离出来,
来自 edit-to.component.ts :-
console.log(this.Todo.todo_title)
有效
但来自 edit-todo.component.html
<input type="text" class="form-control" id="todo_title" [(ngModel)]="title" name="title" value="{{ Todo.todo_title}}">
不起作用