在angular2中更改后重新加载视图数据

在angular2中更改后重新加载视图数据,angular,Angular,我有一个组件,它显示一个对象表,每行有一个按钮,调用一个函数来修改选定对象的属性。即使按钮起作用并且修改了属性,我也必须手动重新加载视图以查看表中的更改 函数如下所示: accept(id: string) { this.service.accept(id).subscribe( data => { console.log('done'); }, error => { consol

我有一个组件,它显示一个对象表,每行有一个按钮,调用一个函数来修改选定对象的属性。即使按钮起作用并且修改了属性,我也必须手动重新加载视图以查看表中的更改

函数如下所示:

accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
        },
        error => {
            console.log('error'):
        });
}
accept(id : string){
    return this.http.put('/myUrl/' +id).map(res => res.json());     
}
accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
            this.getData(); // add your equivalent for fetching data here!
        },
        error => {
            console.log('error'):
        });
}
我的服务上的accept方法如下所示:

accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
        },
        error => {
            console.log('error'):
        });
}
accept(id : string){
    return this.http.put('/myUrl/' +id).map(res => res.json());     
}
accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
            this.getData(); // add your equivalent for fetching data here!
        },
        error => {
            console.log('error'):
        });
}
我希望视图在按下按钮正确显示新值时“重新加载”,而无需手动重新加载页面。这可能吗?或者我做错了什么

编辑1

下面是我提到的带有按钮的html表的更多代码:

<table class="table">
<thead class="thead-default">
        <tr>
            <th>Title</th>
            <th>Date</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let item of items">
            <td>{{item.title}}</td>
            <td>{{item.date| date: 'dd/MM/yyyy'}}</td>
            <td *ngIf="item.status== 0">Pending</td>
            <td *ngIf="item.status== 1">Accepted</td>
            <td *ngIf="item.status== 0">
                <button (click)='accept(item.id)'>Accept</button>
            </td> 
        </tr>
    </tbody>
</table>

标题
日期
地位
{{item.title}
{{item.date}日期:'dd/MM/yyyy'}
悬而未决的
认可的
接受
编辑2

我刚刚意识到在我的原始代码中,在代码的这一部分:

aceptar(id: string) {
    this.propuestaService.aceptarPropuesta(id).subscribe(
        data => {
            this.msg = 'Propuesta Aceptada';
        },
        error => {
            console.log('error'):  <----- Didn't have this here
        });
}
aceptar(id:string){
this.propuestaService.aceptarpopuesta(id).subscribe(
数据=>{
this.msg='Propuesta Aceptada';
},
错误=>{

console.log('error'):进行更改后,您需要从数据库中获取值。如果不通知应用程序这样做,值不会神奇地出现;)这就是为什么在初始化时从数据库中获取值时,在进行硬刷新后,您会看到更改

因此,修改并保存更改后,需要再次调用api以检索值,如下所示:

accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
        },
        error => {
            console.log('error'):
        });
}
accept(id : string){
    return this.http.put('/myUrl/' +id).map(res => res.json());     
}
accept(id: string) {
    this.service.accept(id).subscribe(
        data => {
            console.log('done');
            this.getData(); // add your equivalent for fetching data here!
        },
        error => {
            console.log('error'):
        });
}

嗯,在进行更改后,您必须调用服务从数据库中重新检索值,以便能够看到新值…这不起作用,按下按钮时仍然没有发生任何事情,必须手动重新加载才能看到更改。html表中调用函数modifyAttribute()的按钮点击。请分享更多的代码…这里没有什么需要处理的。你也可以查看changedetector。我用更多的代码编辑了我的问题,我不知道这是否是你需要看到的部分,如果你还需要其他东西,请告诉我。如果状态值为0,按钮基本上会将状态值设置为1,我想要的是表格显示t当我点击它时,它会显示一个新的状态。好吧,我根本看不到代码中任何地方的状态变化,这种变化发生在哪里?