在Angular 2中,根据父模块复选框更改子模块值

时间:2016-12-09 10:34:20

标签: angular angular2-template angular2-material

如果我将switch按钮的值更改为false,则将所有子模块的值更改为false

<div class="content">
  <md-slide-toggle color="primary" [(ngModel)]="permission.permission.department.main" [ngModelOptions]="{standalone: true}">On/Off</md-slide-toggle>
</div>
<div *ngIf="permission.permission.department.main" class="content">
    <md-checkbox [(ngModel)]="permission.permission.department.view" align="end" [ngModelOptions]="{standalone: true}">View</md-checkbox>
    <md-checkbox [(ngModel)]="permission.permission.department.add" align="end" [ngModelOptions]="{standalone: true}">Add</md-checkbox>
    <md-checkbox [(ngModel)]="permission.permission.department.edit" align="end" [ngModelOptions]="{standalone: true}">Edit</md-checkbox>
    <md-checkbox [(ngModel)]="permission.permission.department.delete" align="end" [ngModelOptions]="{standalone: true}">Delete</md-checkbox>    
</div>

1 个答案:

答案 0 :(得分:0)

您可以更新更改功能的值,请检查并告诉我您是否还想要其他内容

<md-slide-toggle color="primary" 
[(ngModel)]="permission.permission.department.main" 
(change)="setValue(permission.permission.department.main,permission.permission.department)" 
[ngModelOptions]="{standalone: true}">On/Off</md-slide-toggle>
你的ts文件中的

添加一个方法

setValue(currentvalue,p){
for (var key in p) {
  if (p.hasOwnProperty(key)) {
    p[key]=currentvalue;
  }
}
}