【发布时间】:2017-10-17 10:49:18
【问题描述】:
我有一个使用Typescript 的Angular 2 应用程序,但我是新手,我有一个带有“删除”按钮的表格,
我可以将对象数据传递给我的确认模式,但是当我“确认”它时,它仍然在我的表格中。
删除-modal.component
import { Component, OnInit, Inject, Input } from '@angular/core';
import { TestService } from '../../ABC/TestService/TestService.service';
import { MdDialog, MdDialogRef, MD_DIALOG_DATA } from '@angular/material';
import { testModal } from 'models/test';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.css']
})
export class testDeleteModalComponent implements OnInit {
@Input('test') test: testModal;
constructor(private TestService: TestService, private accountService: AccountService,
@Inject(MD_DIALOG_DATA) private dialogData: any) { }
ngOnInit() {
console.log('test', this.dialogData.beneficiary);
this.test = this.dialogData.test;
}
deleteTest() {
if (this.dialogData.test.identifier) {
// this.dialogData.beneficiary.splice(this.dialogData.beneficiary.indexOf(this.beneficiaryAnt), 1);
// this.dialogData.beneficiary.splice(this.beneficiary);
// delete this.beneficiary;
this.dialogData.test.splice(this.dialogData.test.indexOf(this.dialogData.test), 1);
} else {
this.dialogData.test.operation = 'X';
}
}
}
HTML
<button md-icon-button (click)="deleteTest()" name="deleteTestDetails">
<md-icon>delete forever</md-icon>
</button>
所有其他HTML 位于主component 中,并使用“删除”按钮,如下所示
<app-test-main-page-delete-button [test]="test"></app-test-main-page-delete-button>
当用户点击确认按钮时调用'deleteTest'方法。
我还在上面列出了我在IF 中尝试过的一些方法,但它们总是会回来
...不是函数
【问题讨论】:
-
你能展示一下你是如何在html中调用这个函数的吗?
-
使用 this.ref.detectChanges();并导入: import { ChangeDetectorRef } from '@angular/core';文档:angular.io/api/core/ChangeDetectorRef
-
可以分享html代码吗?
-
@SurenSrapyan
splice或indexof根据我注释掉的代码 -
@JaroslawK HTML 添加
标签: javascript angular typescript angular2-directives