【问题标题】:Get back to the previous page with the previously entered data in angular 8使用 Angular 8 中先前输入的数据返回上一页
【发布时间】:2021-03-22 20:17:02
【问题描述】:

我在一个页面中有一些文本框和按钮,当单击该按钮时,它应该导航到另一个组件,在完成该页面中的所有功能后,它应该使用先前输入的数据导航回上一页。

我怎么能在 Angular 8 中做到这一点。任何建议。

【问题讨论】:

  • 使用受持久数据约束的行为。另请参阅此链接stackoverflow.com/questions/39762485/…
  • 你如何导航回来?你用{ Router } from '@angular/router'还是{Location} from '@angular/common'
  • 是的,通过使用我要导航到后面的位置,但在我的情况下,有很多数据字段需要用以前输入的数据填充。 @MichaelD

标签: angular angular8 angular2-routing


【解决方案1】:

因此,如果您当时不想将任何数据提交到任何类型的数据库,我建议您使用某种可注入状态服务。

@Injectable({
    providedIn: 'root'
})
export class FormStateService {
    private _formData: FormDataDto | null = null;
    
    public get formData() {
        return this._formData;
    }

    public set formData(form: FormDataDto | null) {
        this._formData = form;
    }
}

单击导航到其他组件的按钮时,使用set 方法保存表单数据。返回原组件时,使用get方法获取表单数据。

【讨论】:

    猜你喜欢
    • 2019-01-26
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    相关资源
    最近更新 更多