Cannot read property 'id' of undefined UsersReportingComponent.html












0















users.reporting.component.html:



<div class="container"

<form (ngSubmit)="processForm()">

<div class="form group" >
<label for="id">Id</label>
<input type="text" name="id" class="form-control" [(ngModel)]="user.id">
</div>
<div class="form group">
<label for="name">Full Name</label>
<input type="text" name="name" class="form-control" [(ngModel)]="user.name">
</div>

<div class="form group">
<label for="email">Email</label>
<input type="email" name="email" class="form-control" [(ngModel)]="user.email">
</div>
<div class="form group">
<label for="date">Joining Date</label>
<input type="date" name="date" class="form-control" [(ngModel)]="user.date">
</div>
<div class="form group">
<label for="address">Addrress</label>
<input type="text" name="address" class="form-control" [(ngModel)]="user.address">
</div>

<div class="form group">
<label for="status">Status</label>
<input type="text" name="status" class="form-control" [(ngModel)]="user.status">
</div>

<input type="submit" value="save" class="btn btn-success">
</form>
</div>


users.reporting.component.ts:



import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/user';
import { UserService } from 'src/app/shared_service/user.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-users-reporting',
templateUrl: './users-reporting.component.html',
styleUrls: ['./users-reporting.component.css']
})
export class UsersReportingComponent implements OnInit {
private user: User;

constructor(private _userService: UserService, private _router: Router) { }

ngOnInit() {
this.user = this._userService.getter();
}
processForm() {
if (this.user.id == undefined) {
this._userService.createUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
} else {
this._userService.updateUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
}
}
}


Please help me out... I have an error in my project, the error is like this:




ERROR TypeError: Cannot read property 'id' of undefined

at Object.eval [as updateDirectives] (UsersReportingComponent.html:53)

at Object.debugUpdateDirectives

at checkAndUpdateView

at callViewAction

at execComponentViewsAction

at checkAndUpdateView

at callViewAction

at execEmbeddedViewsAction

at checkAndUpdateView

at callViewAction











share|improve this question

























  • Are you sure you have a user?

    – Frank Modica
    Nov 14 '18 at 14:33











  • user?.id try making the id optional.

    – Jai
    Nov 14 '18 at 14:35











  • yeah! i have a user

    – Rohit Prajapati
    Nov 14 '18 at 14:40











  • i have tried this user?.id ..but the still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:41











  • Your user is private make it public.

    – Jai
    Nov 14 '18 at 14:43
















0















users.reporting.component.html:



<div class="container"

<form (ngSubmit)="processForm()">

<div class="form group" >
<label for="id">Id</label>
<input type="text" name="id" class="form-control" [(ngModel)]="user.id">
</div>
<div class="form group">
<label for="name">Full Name</label>
<input type="text" name="name" class="form-control" [(ngModel)]="user.name">
</div>

<div class="form group">
<label for="email">Email</label>
<input type="email" name="email" class="form-control" [(ngModel)]="user.email">
</div>
<div class="form group">
<label for="date">Joining Date</label>
<input type="date" name="date" class="form-control" [(ngModel)]="user.date">
</div>
<div class="form group">
<label for="address">Addrress</label>
<input type="text" name="address" class="form-control" [(ngModel)]="user.address">
</div>

<div class="form group">
<label for="status">Status</label>
<input type="text" name="status" class="form-control" [(ngModel)]="user.status">
</div>

<input type="submit" value="save" class="btn btn-success">
</form>
</div>


users.reporting.component.ts:



import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/user';
import { UserService } from 'src/app/shared_service/user.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-users-reporting',
templateUrl: './users-reporting.component.html',
styleUrls: ['./users-reporting.component.css']
})
export class UsersReportingComponent implements OnInit {
private user: User;

constructor(private _userService: UserService, private _router: Router) { }

ngOnInit() {
this.user = this._userService.getter();
}
processForm() {
if (this.user.id == undefined) {
this._userService.createUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
} else {
this._userService.updateUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
}
}
}


Please help me out... I have an error in my project, the error is like this:




ERROR TypeError: Cannot read property 'id' of undefined

at Object.eval [as updateDirectives] (UsersReportingComponent.html:53)

at Object.debugUpdateDirectives

at checkAndUpdateView

at callViewAction

at execComponentViewsAction

at checkAndUpdateView

at callViewAction

at execEmbeddedViewsAction

at checkAndUpdateView

at callViewAction











share|improve this question

























  • Are you sure you have a user?

    – Frank Modica
    Nov 14 '18 at 14:33











  • user?.id try making the id optional.

    – Jai
    Nov 14 '18 at 14:35











  • yeah! i have a user

    – Rohit Prajapati
    Nov 14 '18 at 14:40











  • i have tried this user?.id ..but the still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:41











  • Your user is private make it public.

    – Jai
    Nov 14 '18 at 14:43














0












0








0


1






users.reporting.component.html:



<div class="container"

<form (ngSubmit)="processForm()">

<div class="form group" >
<label for="id">Id</label>
<input type="text" name="id" class="form-control" [(ngModel)]="user.id">
</div>
<div class="form group">
<label for="name">Full Name</label>
<input type="text" name="name" class="form-control" [(ngModel)]="user.name">
</div>

<div class="form group">
<label for="email">Email</label>
<input type="email" name="email" class="form-control" [(ngModel)]="user.email">
</div>
<div class="form group">
<label for="date">Joining Date</label>
<input type="date" name="date" class="form-control" [(ngModel)]="user.date">
</div>
<div class="form group">
<label for="address">Addrress</label>
<input type="text" name="address" class="form-control" [(ngModel)]="user.address">
</div>

<div class="form group">
<label for="status">Status</label>
<input type="text" name="status" class="form-control" [(ngModel)]="user.status">
</div>

<input type="submit" value="save" class="btn btn-success">
</form>
</div>


users.reporting.component.ts:



import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/user';
import { UserService } from 'src/app/shared_service/user.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-users-reporting',
templateUrl: './users-reporting.component.html',
styleUrls: ['./users-reporting.component.css']
})
export class UsersReportingComponent implements OnInit {
private user: User;

constructor(private _userService: UserService, private _router: Router) { }

ngOnInit() {
this.user = this._userService.getter();
}
processForm() {
if (this.user.id == undefined) {
this._userService.createUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
} else {
this._userService.updateUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
}
}
}


Please help me out... I have an error in my project, the error is like this:




ERROR TypeError: Cannot read property 'id' of undefined

at Object.eval [as updateDirectives] (UsersReportingComponent.html:53)

at Object.debugUpdateDirectives

at checkAndUpdateView

at callViewAction

at execComponentViewsAction

at checkAndUpdateView

at callViewAction

at execEmbeddedViewsAction

at checkAndUpdateView

at callViewAction











share|improve this question
















users.reporting.component.html:



<div class="container"

<form (ngSubmit)="processForm()">

<div class="form group" >
<label for="id">Id</label>
<input type="text" name="id" class="form-control" [(ngModel)]="user.id">
</div>
<div class="form group">
<label for="name">Full Name</label>
<input type="text" name="name" class="form-control" [(ngModel)]="user.name">
</div>

<div class="form group">
<label for="email">Email</label>
<input type="email" name="email" class="form-control" [(ngModel)]="user.email">
</div>
<div class="form group">
<label for="date">Joining Date</label>
<input type="date" name="date" class="form-control" [(ngModel)]="user.date">
</div>
<div class="form group">
<label for="address">Addrress</label>
<input type="text" name="address" class="form-control" [(ngModel)]="user.address">
</div>

<div class="form group">
<label for="status">Status</label>
<input type="text" name="status" class="form-control" [(ngModel)]="user.status">
</div>

<input type="submit" value="save" class="btn btn-success">
</form>
</div>


users.reporting.component.ts:



import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/user';
import { UserService } from 'src/app/shared_service/user.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-users-reporting',
templateUrl: './users-reporting.component.html',
styleUrls: ['./users-reporting.component.css']
})
export class UsersReportingComponent implements OnInit {
private user: User;

constructor(private _userService: UserService, private _router: Router) { }

ngOnInit() {
this.user = this._userService.getter();
}
processForm() {
if (this.user.id == undefined) {
this._userService.createUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
} else {
this._userService.updateUser(this.user).subscribe((user) => {
console.log(user);
this._router.navigate(['/user-listing']);
}, (error) => {
console.log(error);
});
}
}
}


Please help me out... I have an error in my project, the error is like this:




ERROR TypeError: Cannot read property 'id' of undefined

at Object.eval [as updateDirectives] (UsersReportingComponent.html:53)

at Object.debugUpdateDirectives

at checkAndUpdateView

at callViewAction

at execComponentViewsAction

at checkAndUpdateView

at callViewAction

at execEmbeddedViewsAction

at checkAndUpdateView

at callViewAction








angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:50









lagom

1




1










asked Nov 14 '18 at 14:32









Rohit PrajapatiRohit Prajapati

84




84













  • Are you sure you have a user?

    – Frank Modica
    Nov 14 '18 at 14:33











  • user?.id try making the id optional.

    – Jai
    Nov 14 '18 at 14:35











  • yeah! i have a user

    – Rohit Prajapati
    Nov 14 '18 at 14:40











  • i have tried this user?.id ..but the still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:41











  • Your user is private make it public.

    – Jai
    Nov 14 '18 at 14:43



















  • Are you sure you have a user?

    – Frank Modica
    Nov 14 '18 at 14:33











  • user?.id try making the id optional.

    – Jai
    Nov 14 '18 at 14:35











  • yeah! i have a user

    – Rohit Prajapati
    Nov 14 '18 at 14:40











  • i have tried this user?.id ..but the still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:41











  • Your user is private make it public.

    – Jai
    Nov 14 '18 at 14:43

















Are you sure you have a user?

– Frank Modica
Nov 14 '18 at 14:33





Are you sure you have a user?

– Frank Modica
Nov 14 '18 at 14:33













user?.id try making the id optional.

– Jai
Nov 14 '18 at 14:35





user?.id try making the id optional.

– Jai
Nov 14 '18 at 14:35













yeah! i have a user

– Rohit Prajapati
Nov 14 '18 at 14:40





yeah! i have a user

– Rohit Prajapati
Nov 14 '18 at 14:40













i have tried this user?.id ..but the still same error

– Rohit Prajapati
Nov 14 '18 at 14:41





i have tried this user?.id ..but the still same error

– Rohit Prajapati
Nov 14 '18 at 14:41













Your user is private make it public.

– Jai
Nov 14 '18 at 14:43





Your user is private make it public.

– Jai
Nov 14 '18 at 14:43












3 Answers
3






active

oldest

votes


















0














You never set user:



export class UsersReportingComponent implements OnInit {
user: User = new User();

//...
}


Make sure to initialise your class fields before ngOnInit by setting it in the constructor or directly on the field, or use the ?. save navigation operator inside your template: [(ngModel)]="user?.id"



Also as stated in the comments, don't make your user field private, because otherwise the AOT compilation will fail






share|improve this answer


























  • i have tried this also ...but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:39











  • I've updated my answer

    – PierreDuc
    Nov 14 '18 at 14:45











  • sir ..still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54











  • @RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

    – PierreDuc
    Nov 14 '18 at 14:56













  • sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

    – Rohit Prajapati
    Nov 14 '18 at 15:13





















0














It seems to me that you have to change this:



private user: User;


to this:



public user: User;


Private properties are only available inside the class but template is outside.






share|improve this answer
























  • thanks for respond sir...but i have still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:48











  • @RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

    – Jai
    Nov 14 '18 at 14:50











  • yes @Jai sir ...i have tried every solution but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54



















0














It looks like you are retrieving user data using this._userService.getter(); in ngOnInit(). You could use *ngIf to test whether the user has been loaded prior to rendering the form to avoid this error:



<form (ngSubmit)="processForm()" *ngIf="user">
// ...
</form>


Another option would be to simply initialize some default values like '' for string for the user object until the getter() has resolved:



user: User = {
id: 42,
name: '',
email: '',
// ... remaining properties
}


Also, are you sure you are using getter() correctly? Assuming your call is something along the lines of:



getter()
return this.http.get<User>('/some/api/url')
}


You'd consume that like:



ngOnInit() {
this._userService.getter().subcribe(user => this.user = user);
}


Hopefully that helps!






share|improve this answer


























  • getter(){ return this.user; }

    – Rohit Prajapati
    Nov 14 '18 at 15:05











  • ngOnInit() { this.user = this._userService.getter(); }

    – Rohit Prajapati
    Nov 14 '18 at 15:06











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302598%2fcannot-read-property-id-of-undefined-usersreportingcomponent-html%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You never set user:



export class UsersReportingComponent implements OnInit {
user: User = new User();

//...
}


Make sure to initialise your class fields before ngOnInit by setting it in the constructor or directly on the field, or use the ?. save navigation operator inside your template: [(ngModel)]="user?.id"



Also as stated in the comments, don't make your user field private, because otherwise the AOT compilation will fail






share|improve this answer


























  • i have tried this also ...but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:39











  • I've updated my answer

    – PierreDuc
    Nov 14 '18 at 14:45











  • sir ..still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54











  • @RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

    – PierreDuc
    Nov 14 '18 at 14:56













  • sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

    – Rohit Prajapati
    Nov 14 '18 at 15:13


















0














You never set user:



export class UsersReportingComponent implements OnInit {
user: User = new User();

//...
}


Make sure to initialise your class fields before ngOnInit by setting it in the constructor or directly on the field, or use the ?. save navigation operator inside your template: [(ngModel)]="user?.id"



Also as stated in the comments, don't make your user field private, because otherwise the AOT compilation will fail






share|improve this answer


























  • i have tried this also ...but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:39











  • I've updated my answer

    – PierreDuc
    Nov 14 '18 at 14:45











  • sir ..still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54











  • @RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

    – PierreDuc
    Nov 14 '18 at 14:56













  • sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

    – Rohit Prajapati
    Nov 14 '18 at 15:13
















0












0








0







You never set user:



export class UsersReportingComponent implements OnInit {
user: User = new User();

//...
}


Make sure to initialise your class fields before ngOnInit by setting it in the constructor or directly on the field, or use the ?. save navigation operator inside your template: [(ngModel)]="user?.id"



Also as stated in the comments, don't make your user field private, because otherwise the AOT compilation will fail






share|improve this answer















You never set user:



export class UsersReportingComponent implements OnInit {
user: User = new User();

//...
}


Make sure to initialise your class fields before ngOnInit by setting it in the constructor or directly on the field, or use the ?. save navigation operator inside your template: [(ngModel)]="user?.id"



Also as stated in the comments, don't make your user field private, because otherwise the AOT compilation will fail







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 14:44

























answered Nov 14 '18 at 14:36









PierreDucPierreDuc

29.9k55878




29.9k55878













  • i have tried this also ...but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:39











  • I've updated my answer

    – PierreDuc
    Nov 14 '18 at 14:45











  • sir ..still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54











  • @RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

    – PierreDuc
    Nov 14 '18 at 14:56













  • sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

    – Rohit Prajapati
    Nov 14 '18 at 15:13





















  • i have tried this also ...but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:39











  • I've updated my answer

    – PierreDuc
    Nov 14 '18 at 14:45











  • sir ..still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54











  • @RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

    – PierreDuc
    Nov 14 '18 at 14:56













  • sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

    – Rohit Prajapati
    Nov 14 '18 at 15:13



















i have tried this also ...but still same error

– Rohit Prajapati
Nov 14 '18 at 14:39





i have tried this also ...but still same error

– Rohit Prajapati
Nov 14 '18 at 14:39













I've updated my answer

– PierreDuc
Nov 14 '18 at 14:45





I've updated my answer

– PierreDuc
Nov 14 '18 at 14:45













sir ..still same error

– Rohit Prajapati
Nov 14 '18 at 14:54





sir ..still same error

– Rohit Prajapati
Nov 14 '18 at 14:54













@RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

– PierreDuc
Nov 14 '18 at 14:56







@RohitPrajapati then you have not posted the entire template, the error seems to be at line 53 of your template. Or your userService.getter() is not returning a user but undefined

– PierreDuc
Nov 14 '18 at 14:56















sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

– Rohit Prajapati
Nov 14 '18 at 15:13







sir this is at line 53: <input type="text" name="id" class="form-control" [(ngModel)]="user.id">

– Rohit Prajapati
Nov 14 '18 at 15:13















0














It seems to me that you have to change this:



private user: User;


to this:



public user: User;


Private properties are only available inside the class but template is outside.






share|improve this answer
























  • thanks for respond sir...but i have still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:48











  • @RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

    – Jai
    Nov 14 '18 at 14:50











  • yes @Jai sir ...i have tried every solution but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54
















0














It seems to me that you have to change this:



private user: User;


to this:



public user: User;


Private properties are only available inside the class but template is outside.






share|improve this answer
























  • thanks for respond sir...but i have still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:48











  • @RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

    – Jai
    Nov 14 '18 at 14:50











  • yes @Jai sir ...i have tried every solution but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54














0












0








0







It seems to me that you have to change this:



private user: User;


to this:



public user: User;


Private properties are only available inside the class but template is outside.






share|improve this answer













It seems to me that you have to change this:



private user: User;


to this:



public user: User;


Private properties are only available inside the class but template is outside.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 14:45









JaiJai

64.1k95480




64.1k95480













  • thanks for respond sir...but i have still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:48











  • @RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

    – Jai
    Nov 14 '18 at 14:50











  • yes @Jai sir ...i have tried every solution but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54



















  • thanks for respond sir...but i have still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:48











  • @RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

    – Jai
    Nov 14 '18 at 14:50











  • yes @Jai sir ...i have tried every solution but still same error

    – Rohit Prajapati
    Nov 14 '18 at 14:54

















thanks for respond sir...but i have still same error

– Rohit Prajapati
Nov 14 '18 at 14:48





thanks for respond sir...but i have still same error

– Rohit Prajapati
Nov 14 '18 at 14:48













@RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

– Jai
Nov 14 '18 at 14:50





@RohitPrajapati then it looks like the other answer is the solution for your issue. Did you try that?

– Jai
Nov 14 '18 at 14:50













yes @Jai sir ...i have tried every solution but still same error

– Rohit Prajapati
Nov 14 '18 at 14:54





yes @Jai sir ...i have tried every solution but still same error

– Rohit Prajapati
Nov 14 '18 at 14:54











0














It looks like you are retrieving user data using this._userService.getter(); in ngOnInit(). You could use *ngIf to test whether the user has been loaded prior to rendering the form to avoid this error:



<form (ngSubmit)="processForm()" *ngIf="user">
// ...
</form>


Another option would be to simply initialize some default values like '' for string for the user object until the getter() has resolved:



user: User = {
id: 42,
name: '',
email: '',
// ... remaining properties
}


Also, are you sure you are using getter() correctly? Assuming your call is something along the lines of:



getter()
return this.http.get<User>('/some/api/url')
}


You'd consume that like:



ngOnInit() {
this._userService.getter().subcribe(user => this.user = user);
}


Hopefully that helps!






share|improve this answer


























  • getter(){ return this.user; }

    – Rohit Prajapati
    Nov 14 '18 at 15:05











  • ngOnInit() { this.user = this._userService.getter(); }

    – Rohit Prajapati
    Nov 14 '18 at 15:06
















0














It looks like you are retrieving user data using this._userService.getter(); in ngOnInit(). You could use *ngIf to test whether the user has been loaded prior to rendering the form to avoid this error:



<form (ngSubmit)="processForm()" *ngIf="user">
// ...
</form>


Another option would be to simply initialize some default values like '' for string for the user object until the getter() has resolved:



user: User = {
id: 42,
name: '',
email: '',
// ... remaining properties
}


Also, are you sure you are using getter() correctly? Assuming your call is something along the lines of:



getter()
return this.http.get<User>('/some/api/url')
}


You'd consume that like:



ngOnInit() {
this._userService.getter().subcribe(user => this.user = user);
}


Hopefully that helps!






share|improve this answer


























  • getter(){ return this.user; }

    – Rohit Prajapati
    Nov 14 '18 at 15:05











  • ngOnInit() { this.user = this._userService.getter(); }

    – Rohit Prajapati
    Nov 14 '18 at 15:06














0












0








0







It looks like you are retrieving user data using this._userService.getter(); in ngOnInit(). You could use *ngIf to test whether the user has been loaded prior to rendering the form to avoid this error:



<form (ngSubmit)="processForm()" *ngIf="user">
// ...
</form>


Another option would be to simply initialize some default values like '' for string for the user object until the getter() has resolved:



user: User = {
id: 42,
name: '',
email: '',
// ... remaining properties
}


Also, are you sure you are using getter() correctly? Assuming your call is something along the lines of:



getter()
return this.http.get<User>('/some/api/url')
}


You'd consume that like:



ngOnInit() {
this._userService.getter().subcribe(user => this.user = user);
}


Hopefully that helps!






share|improve this answer















It looks like you are retrieving user data using this._userService.getter(); in ngOnInit(). You could use *ngIf to test whether the user has been loaded prior to rendering the form to avoid this error:



<form (ngSubmit)="processForm()" *ngIf="user">
// ...
</form>


Another option would be to simply initialize some default values like '' for string for the user object until the getter() has resolved:



user: User = {
id: 42,
name: '',
email: '',
// ... remaining properties
}


Also, are you sure you are using getter() correctly? Assuming your call is something along the lines of:



getter()
return this.http.get<User>('/some/api/url')
}


You'd consume that like:



ngOnInit() {
this._userService.getter().subcribe(user => this.user = user);
}


Hopefully that helps!







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 15:02

























answered Nov 14 '18 at 14:55









Alexander StaroselskyAlexander Staroselsky

12.8k42040




12.8k42040













  • getter(){ return this.user; }

    – Rohit Prajapati
    Nov 14 '18 at 15:05











  • ngOnInit() { this.user = this._userService.getter(); }

    – Rohit Prajapati
    Nov 14 '18 at 15:06



















  • getter(){ return this.user; }

    – Rohit Prajapati
    Nov 14 '18 at 15:05











  • ngOnInit() { this.user = this._userService.getter(); }

    – Rohit Prajapati
    Nov 14 '18 at 15:06

















getter(){ return this.user; }

– Rohit Prajapati
Nov 14 '18 at 15:05





getter(){ return this.user; }

– Rohit Prajapati
Nov 14 '18 at 15:05













ngOnInit() { this.user = this._userService.getter(); }

– Rohit Prajapati
Nov 14 '18 at 15:06





ngOnInit() { this.user = this._userService.getter(); }

– Rohit Prajapati
Nov 14 '18 at 15:06


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302598%2fcannot-read-property-id-of-undefined-usersreportingcomponent-html%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python