Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular TypeError:无法读取属性';长度';角4中未定义的_Angular_Primeng - Fatal编程技术网

Angular TypeError:无法读取属性';长度';角4中未定义的

Angular TypeError:无法读取属性';长度';角4中未定义的,angular,primeng,Angular,Primeng,TypeError:无法读取角度4中未定义的属性“长度” 这是密码 导出类UserComponent实现OnInit{ roles:IUserRole[]; sourseRoles: SelectedItem[]; selectedRole:any; BindRoles() { this.sourseRoles= []; this.sourseRoles.push({ label: "Assign Role", value: null }); if (thi

TypeError:无法读取角度4中未定义的属性“长度”

这是密码 导出类UserComponent实现OnInit{

  roles:IUserRole[];
  sourseRoles: SelectedItem[];
  selectedRole:any;

BindRoles() {
    this.sourseRoles= [];
    this.sourseRoles.push({ label: "Assign Role", value: null });
    if (this.roles.length > 0) {
      for (let role of this.roles) {
        this.sourseRoles.push({ label: role.Title, value: role.UserRoleId })enter image description here
      }
    }
  }
----------
这是密码

this.appServiceManager.libGet(“角色”) .订阅((角色:任意)=>{ this.selectedRole=[]

           this.selectedRole = role;
           this.sourseRoles.push({ label: this.selectedRole.Title, value: this.selectedRole.UserRoleId })
         },
         (error: any) => {
           this.msgs = [];

           this.msgs.push({ severity: 'error', summary: 'Error Message', detail: error });
         });
----------
用户角色
角色
信息是必需的
----------

我在TS代码中看不到这一点:

sourseRoles
我看到了您的角色和selectedRole

导出类UserComponent实现OnInit{
export class UserComponent implements OnInit {
    roles: IUserRole[] = [];     <======= Initialize it =========>
    sourseRoles: SelectedItem[]; <======= Declaration was incorrect =========>
    selectedRole: any;

    BindRoles() {
      if (this.roles.length > 0) {
        for (let role of this.roles) {
          this.sourseRoles.push({ label: role.Title, value: role.UserRoleId })
        }
      }
    }
}
角色:IUserRole[]=[]; sourseRoles:SelectedItem[]; selectedRole:任意; BindRoles(){ 如果(this.roles.length>0){ for(让角色成为this.roles的角色){ this.sourseRoles.push({label:role.Title,value:role.UserRoleId}) } } } }
初始化角色的值。…。@Jota.Toledo是正确的。您应该初始化角色数组,否则您将拥有该值error@mahsam对不起,我不再写sourseRoles plz了,我编辑了这个帖子,我通过webapi服务获取角色
export class UserComponent implements OnInit {
    roles: IUserRole[] = [];     <======= Initialize it =========>
    sourseRoles: SelectedItem[]; <======= Declaration was incorrect =========>
    selectedRole: any;

    BindRoles() {
      if (this.roles.length > 0) {
        for (let role of this.roles) {
          this.sourseRoles.push({ label: role.Title, value: role.UserRoleId })
        }
      }
    }
}