Twitter bootstrap 如何在angular 2中向引导模式传递值
我想将一个值传递给我的引导模式。在angular2应用程序中。我怎样才能做到这一点?。这是我的密码Twitter bootstrap 如何在angular 2中向引导模式传递值,twitter-bootstrap,angular,typescript,Twitter Bootstrap,Angular,Typescript,我想将一个值传递给我的引导模式。在angular2应用程序中。我怎样才能做到这一点?。这是我的密码 <button href="" class="ui red button" [attr.data-index]="i" data-toggle="modal" data-target="#deleteVersion" data-backdrop="static">Delete</button> &l
<button href="" class="ui red button"
[attr.data-index]="i"
data-toggle="modal"
data-target="#deleteVersion"
data-backdrop="static">Delete</button>
<confirm-dialog [id]="'deleteVersion'" [title]="'Delete Version'" [content]="'Do you want to delete this version ?'" [positiveCall]="deleteVersion.bind(this)"></confirm-dialog>
@Component({
selector: 'confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.css']
})
export class ConfirmDialogComponent implements OnInit {
@Input()
id: String;
@Input()
title: String;
@Input()
content: String;
@Input()
positiveCall: Function;
constructor() { }
ngOnInit() {
}
yes() {
this.positiveCall = this.positiveCall || function () { };
this.positiveCall();
}
}
删除
@组成部分({
选择器:“确认对话框”,
templateUrl:“./confirm dialog.component.html”,
样式URL:['./确认对话框.component.css']
})
导出类ConfirmDialogComponent实现OnInit{
@输入()
id:字符串;
@输入()
标题:字符串;
@输入()
内容:字符串;
@输入()
正调用:函数;
构造函数(){}
恩戈尼尼特(){
}
是(){
this.positiveCall=this.positiveCall | |函数(){};
这个.positiveCall();
}
}
我想在
ngFor
中传递索引,提前感谢如果您只想访问ngFor
中的索引,您可以通过将变量分配给索引来访问它
<button href="" class="ui red button"
data-toggle="modal"
data-target="#deleteVersion"
data-backdrop="static"
(click)="selectedIndex = i">Delete</button>
<confirm-dialog [index]="selectedIndex" [id]="'deleteVersion'" [title]="'Delete Version'" [content]="'Do you want to delete this version ?'" [positiveCall]="deleteVersion.bind(this)"></confirm-dialog>
@Component({
selector: 'confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.css']
})
export class ConfirmDialogComponent implements OnInit {
@Input()
id: String;
@Input()
title: String;
@Input()
content: String;
@Input()
positiveCall: Function;
selectedIndex: number;
constructor() { }
ngOnInit() {
}
yes() {
this.positiveCall = this.positiveCall || function () { };
this.positiveCall();
}
}
设置一个组件属性selectedIndex
,然后单击打开模式的按钮,将该值设置为适当的索引
您的代码中缺少一个ngFor
,因此只需假设中的i
(单击)=“selectedIndex=i”
是从*ngFor=“let item of items;let i=index”中的i
派生出来的
删除
@组成部分({
选择器:“确认对话框”,
templateUrl:“./confirm dialog.component.html”,
样式URL:['./确认对话框.component.css']
})
导出类ConfirmDialogComponent实现OnInit{
@输入()
id:字符串;
@输入()
标题:字符串;
@输入()
内容:字符串;
@输入()
正调用:函数;
selectedIndex:编号;
构造函数(){}
恩戈尼尼特(){
}
是(){
this.positiveCall=this.positiveCall | |函数(){};
这个.positiveCall();
}
}
您是如何使用modal的?您只是在引导中以正常方式使用它,还是在角度代码中创建了一些ModalService/ModalComponent类型的行为?请提供更多信息?我使用的是正常引导模型,带有自定义组件。您在哪里使用ngFor
?在问题描述中添加该代码。我想删除ngFor中的一个项目,我想从ngFor中删除id
或index
,我想将该索引传递到我的模型。您应该能够通过使用j
作为参数来传递它,P.S:我仍然看不到您在哪里/如何实现*ngFor
。请将其添加到您的代码中。如何传递多个值而不是像我的示例中那样传递[index]
,可以创建一个对象并将整个对象作为[data]
@输入或其他内容传递。该对象可以包含您的索引和您需要的任何其他信息。