将Primeng升级到版本9后无法呈现页面

时间:2020-10-16 10:59:03

标签: angular primeng primeng-datatable

将项目升级到Angular 9之后,我将Prime的二手组件从Priment从p-dataTable更改为p-Table,如Primeng的文档所述。不幸的是,现在我的页面无法呈现。以HTML格式

<p-table [value]="popup.assignedUser.selectedList" [scrollable]="true"

此行说assignedUser是未定义的,但是在带有旧Primeng dataTable和angular 6的早期版本中,这很好用。我应该更改什么,使代码与之前的Primeng Table一样工作? 在该html的ts中,我已经声明了

 @ViewChild('popup', {static: false}) popup: UsersPopupComponent;

弹出组件如下:

  @ViewChild('userModal') userModal;
    @ViewChild('assignedUser') assignedUser: AssignedUserTableComponent;
    @ViewChild('assignUser') assignUser;
    type = globals.viewType;
    reportView = false;

    constructor(private reportsComponent: ReportsComponent) {
    }

    openModal(): void {
        this.reportView = true;
        this.userModal.nativeElement.classList.add('open-modal');
    }

    closeModal() {
        this.userModal.nativeElement.classList.remove('open-modal');
    }

    refreshTree() {
        this.assignUser.refreshTree(this.assignUser.treeSelect);

    }

    gatherData() {
        this.reportsComponent.gatherUserIds();
    }

    deleteList() {
        this.assignedUser.selectedList = [];
    }

和AssignedUser中的selectedList设置在另一个组件AssignedUserTable中

 addUser(inputList) {
        if (this.typeService === this.typeInput) {
            inputList.forEach(il => (
                !this.selectedList.find(sl => sl.userId === il.userId)) ?
                this.selectedList.push(il) : {});
            this.emitUser();
            this.selectedList.forEach(user => {
                user._fullName = this.userService.getUserFullNameFromCachedUsers(user.userId);
            });
            this.selectedList.sort((a, b) =>
                a._fullName.substr(a._fullName.indexOf(' ') + 1).localeCompare(b._fullName.substr(b._fullName.indexOf(' ') + 1)));
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试在HTML中的AssignedUser之后添加问号。基本上问号是

if assignedUser !== undefined && assignedUser !== null

<p-table [value]="popup.assignedUser?.selectedList" [scrollable]="true"

如果在视图之后启动了assigneUser,则该视图将具有未定义的对象。有了这个技巧,它将等待有一个值来初始化。