如何显示从数据库获取的用于角度双向绑定的初始值

问题描述 投票:0回答:1

我想创建一个更新页面,用户可以为其更新Recipe值。我知道如何使用双向数据绑定来创建新的Recipe,但是如何加载一个页面,该页面具有从数据库中获取的值,这些页面最初已加载到输入字段中?

所以我有一个示范食谱

export class Recipe {
  constructor(
      public name: String
  ) {}
}

在RecipeComponent中]

import { Recipe } from './Recipe';

export class RecipeComponent {
  data = new Recipe('');
}

以html格式显示

<input type="text" class="form-control" id="name" 
  required
  [(ngModel)]="data.name" />

<p>Hello {{ data.name }}!</p>

如果我想从头开始创建新模型,这很好用。但是我希望用户能够看到存在的值,因此我希望在data = new Recipe('')行中使用RecipeService来填充输入。

我想创建一个更新页面,用户可以为其更新配方值。我知道如何使用双向数据绑定来创建新配方,但是如何加载具有从...

angular angular-ngmodel
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.