I am getting error while i call push method

ng:///AppModule/ManageUser_Host.ngfactory.js:5 ERROR TypeError: Cannot read property 'push' of undefined
    at ManageUser.push../src/app/Views/user/user.component.ts.ManageUser.getUsers (main.js:7277)
    at ManageUser.push../src/app/Views/user/user.component.ts.ManageUser.ngOnInit (main.js:7271)
    at checkAndUpdateDirectiveInline (vendor.js:73109)
    at checkAndUpdateNodeInline (vendor.js:74633)
    at checkAndUpdateNode (vendor.js:74576)
    at debugCheckAndUpdateNode (vendor.js:75469)
    at debugCheckDirectivesFn (vendor.js:75410)
    at Object.eval [as updateDirectives] (ng:///AppModule/ManageUser_Host.ngfactory.js:9)
    at Object.debugUpdateDirectives [as updateDirectives] (vendor.js:75395)
    at checkAndUpdateView (vendor.js:74542)

Code is shown below:

public users: User[];

this.users.push({"UserId":2,"FirstName":"string","FullName":"string","LastName":"string","EmailAddress":"string",
        "GEID":"string",
        "RITSID":"string",
        "SOEID":"string",
        "RoleID": 1,
        "RoleName":"string",
        "IsActive":true,
        "ModifyingUserId":"string",
        "CreatedBy":"string",
        "CreatedDate":"string",
        "EmailID":"string",       
        "Name": "string",
        "Email": "string",
        "Roles":"any",
        "Manager":"string"});

    console.log(this.users);

1 Answers

6
ganesh045 On

you are just defining it so it's by default the value is undefined

  public users: User[];

just add a value to it and try again

public users: User[]= [];

happy coding. :)