gpt4 book ai didi

angular - 无法设置 Angular 未定义错误的属性 'nUserId'

转载 作者:行者123 更新时间:2023-12-01 21:24:25 25 4
gpt4 key购买 nike

当我的表单复选框切换时,我试图调用一个 ReST API。当我调用调用 api 的方法时,我收到类似

的错误
Cannot set property 'nUserId' of undefined at

我的 html 文件包含以下代码,

<div>
<button mat-raised-button color="primary" (click)="getUserPermisionsByUsernameSearch()">
Search</button>
</div>
<br /> <br><br />
<div *ngIf="userPermissionObj">
<div><label for="pl">Permission Level:</label> {{userPermissionObj.sPermLevel}} </div>
<label for="pm">Permissions:</label>
<div *ngFor="let pt of permissionType">
<label>
<input type="checkbox" [value]="pt.id" [checked]="userPermissionObj.sPermissionType == pt.name ? true : false"
(change)="updateUserPermisionsByUsername(userPermissionObj,pt)" />
{{pt.name}} -- {{userPermissionObj.nUserId}}
</label>

我的ts文件包含以下代码,

export class ModifyuserpermissionsComponent implements OnInit {
selectedUser: string;
selectedInstitution: string;
filtertext: string;
public status: boolean = false;
public data = new Array();

institutionalUsers: any;
userNameDetails: any;
userPermissionObj: any;
permissionRequestUser: any;
modificationObj: any;
userObj: any;
permision: any;


dataSource = new MatTableDataSource();
selection = new SelectionModel<Element>(true, []);
displayedColumns = ['UserId', 'PermissionId', 'PermissionLevel', 'PermissionType'];


constructor(public dialog: MatDialog,
public manageuserService: ManageuserService) { }

ngOnInit() {

this.manageuserService.loadUserListApiMethod()
.subscribe((data: any) => { this.institutionalUsers = data });
}
loadUserForSearchPermission(event: any, obj: any) {
if (event.isUserInput) {
this.permissionRequestUser = obj.sUsername;
}
}

permissionType = [
{ id: 1, name: 'R' },
{ id: 2, name: 'W' }
];

getUserPermisionsByUsernameSearch() {
var param: string = this.permissionRequestUser;
this.manageuserService.getUserPermissionApiMethod(param)
.subscribe((data: any) => { this.userPermissionObj = data });
}

updateUserPermisionsByUsername(userObj, permision) {
this.modificationObj.nUserId = userObj.nUserId;
this.modificationObj.name = permision.name;
this.manageuserService.modifyUserPermissionApiMethod(this.userObj)
.subscribe((data: any) => { this.institutionalUsers = data });
}

}

有人可以指导我在这里找到错误的实现吗?

最佳答案

你是否初始化了modificationObj

您正在尝试设置 undefined 对象的属性。它应该如下所示:

updateUserPermisionsByUsername(userObj, permision) {
// this.modificationObj.nUserId = userObj.nUserId;
// this.modificationObj.name = permision.name;

this.modificationObj = {
nUserId: userObj.nUserId,
name: permision.name
}
}

关于angular - 无法设置 Angular 未定义错误的属性 'nUserId',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63263369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com