I delete a datarow from my database but not from my webpage until i refresh it. How can i delete that row...
i'm using WebApi for backend and Angular 5 for frontend, webapi are connected to a DB from which I take the data to be included in my site.
When i press on "delete" button, the data is delited from my database but not from my webpages, and in Angular(as far as I know, I'm a beginner) the page would be refresh instantly.
Console didn't gave me an error so i think probably it's a route configuration error. Maybe i would use the ActivatedRoute, because the page has
RouterModule.forChild([
{path:'mioprofilo', component: MyProfileComponent},
Anyway my deleted method in my-profile.component.service.ts is:
deleteRelative(id: number): Observable<Relative>{
const url = `${this.relativeUrl}/${id}`;
return this.http.delete<Relative>(url).pipe(
tap(rel => console.log( `deleted relative id=${id}`)),
catchError(this.handleError)
);
}
And this is the method i call with the click event in my-profile.component.ts:
delete(id:number): void {
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;
});
That is my-profile.component.html with a ngif to test the presence of the data in db and an ngfor* to create a table with the db data:
<table *ngIf = 'relatives && relatives.length'
class="table" id="myTable" style="margin:20px; width: 90%;border-style: outset">
<thead>
<tr>
<th>Cognome</th>
<th>Nome</th>
<th>Telefono</th>
<th>Relazione</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor ='let rel of relatives'>
<td>{{rel.lastName}}</td>
<!-- <td><input type="text" name="name" [(ngModel)]=rel.lastName></td> -->
<td>{{rel.firstName}}</td>
<td>{{rel.phone}}</td>
<td>{{rel.relationType}}</td>
<td>
<a (click)="delete(rel.relativeId)" ><img src="/Images/elimina.png"/></a>
</td>
<td>
<input class="Caregiver" type="checkbox" value="Caregiver">
<span>Caregiver</span>
</td>
</tr>
</tbody>
</table>
I think can be useful to find help me to find a solution if i post below my app.component.module.ts:
@NgModule({
declarations: [
AppComponent,
WelcomeComponent//,
//CalendarComponent,
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot([
{path: 'home', component: WelcomeComponent},
{path: '', redirectTo:'home',pathMatch:'full'},
{path:'**', redirectTo:'home', pathMatch:'full'}
]),
MyProfileModule,
CalendarModule
],
providers: ,
bootstrap: [AppComponent]
})
export class AppModule { }
If you need some other code from me do not be afraid to ask me.
WebApi work very good so the problem must be in my angular code.
Thanks all!
database angular asp.net-web-api routes http-delete
add a comment |
i'm using WebApi for backend and Angular 5 for frontend, webapi are connected to a DB from which I take the data to be included in my site.
When i press on "delete" button, the data is delited from my database but not from my webpages, and in Angular(as far as I know, I'm a beginner) the page would be refresh instantly.
Console didn't gave me an error so i think probably it's a route configuration error. Maybe i would use the ActivatedRoute, because the page has
RouterModule.forChild([
{path:'mioprofilo', component: MyProfileComponent},
Anyway my deleted method in my-profile.component.service.ts is:
deleteRelative(id: number): Observable<Relative>{
const url = `${this.relativeUrl}/${id}`;
return this.http.delete<Relative>(url).pipe(
tap(rel => console.log( `deleted relative id=${id}`)),
catchError(this.handleError)
);
}
And this is the method i call with the click event in my-profile.component.ts:
delete(id:number): void {
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;
});
That is my-profile.component.html with a ngif to test the presence of the data in db and an ngfor* to create a table with the db data:
<table *ngIf = 'relatives && relatives.length'
class="table" id="myTable" style="margin:20px; width: 90%;border-style: outset">
<thead>
<tr>
<th>Cognome</th>
<th>Nome</th>
<th>Telefono</th>
<th>Relazione</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor ='let rel of relatives'>
<td>{{rel.lastName}}</td>
<!-- <td><input type="text" name="name" [(ngModel)]=rel.lastName></td> -->
<td>{{rel.firstName}}</td>
<td>{{rel.phone}}</td>
<td>{{rel.relationType}}</td>
<td>
<a (click)="delete(rel.relativeId)" ><img src="/Images/elimina.png"/></a>
</td>
<td>
<input class="Caregiver" type="checkbox" value="Caregiver">
<span>Caregiver</span>
</td>
</tr>
</tbody>
</table>
I think can be useful to find help me to find a solution if i post below my app.component.module.ts:
@NgModule({
declarations: [
AppComponent,
WelcomeComponent//,
//CalendarComponent,
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot([
{path: 'home', component: WelcomeComponent},
{path: '', redirectTo:'home',pathMatch:'full'},
{path:'**', redirectTo:'home', pathMatch:'full'}
]),
MyProfileModule,
CalendarModule
],
providers: ,
bootstrap: [AppComponent]
})
export class AppModule { }
If you need some other code from me do not be afraid to ask me.
WebApi work very good so the problem must be in my angular code.
Thanks all!
database angular asp.net-web-api routes http-delete
add a comment |
i'm using WebApi for backend and Angular 5 for frontend, webapi are connected to a DB from which I take the data to be included in my site.
When i press on "delete" button, the data is delited from my database but not from my webpages, and in Angular(as far as I know, I'm a beginner) the page would be refresh instantly.
Console didn't gave me an error so i think probably it's a route configuration error. Maybe i would use the ActivatedRoute, because the page has
RouterModule.forChild([
{path:'mioprofilo', component: MyProfileComponent},
Anyway my deleted method in my-profile.component.service.ts is:
deleteRelative(id: number): Observable<Relative>{
const url = `${this.relativeUrl}/${id}`;
return this.http.delete<Relative>(url).pipe(
tap(rel => console.log( `deleted relative id=${id}`)),
catchError(this.handleError)
);
}
And this is the method i call with the click event in my-profile.component.ts:
delete(id:number): void {
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;
});
That is my-profile.component.html with a ngif to test the presence of the data in db and an ngfor* to create a table with the db data:
<table *ngIf = 'relatives && relatives.length'
class="table" id="myTable" style="margin:20px; width: 90%;border-style: outset">
<thead>
<tr>
<th>Cognome</th>
<th>Nome</th>
<th>Telefono</th>
<th>Relazione</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor ='let rel of relatives'>
<td>{{rel.lastName}}</td>
<!-- <td><input type="text" name="name" [(ngModel)]=rel.lastName></td> -->
<td>{{rel.firstName}}</td>
<td>{{rel.phone}}</td>
<td>{{rel.relationType}}</td>
<td>
<a (click)="delete(rel.relativeId)" ><img src="/Images/elimina.png"/></a>
</td>
<td>
<input class="Caregiver" type="checkbox" value="Caregiver">
<span>Caregiver</span>
</td>
</tr>
</tbody>
</table>
I think can be useful to find help me to find a solution if i post below my app.component.module.ts:
@NgModule({
declarations: [
AppComponent,
WelcomeComponent//,
//CalendarComponent,
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot([
{path: 'home', component: WelcomeComponent},
{path: '', redirectTo:'home',pathMatch:'full'},
{path:'**', redirectTo:'home', pathMatch:'full'}
]),
MyProfileModule,
CalendarModule
],
providers: ,
bootstrap: [AppComponent]
})
export class AppModule { }
If you need some other code from me do not be afraid to ask me.
WebApi work very good so the problem must be in my angular code.
Thanks all!
database angular asp.net-web-api routes http-delete
i'm using WebApi for backend and Angular 5 for frontend, webapi are connected to a DB from which I take the data to be included in my site.
When i press on "delete" button, the data is delited from my database but not from my webpages, and in Angular(as far as I know, I'm a beginner) the page would be refresh instantly.
Console didn't gave me an error so i think probably it's a route configuration error. Maybe i would use the ActivatedRoute, because the page has
RouterModule.forChild([
{path:'mioprofilo', component: MyProfileComponent},
Anyway my deleted method in my-profile.component.service.ts is:
deleteRelative(id: number): Observable<Relative>{
const url = `${this.relativeUrl}/${id}`;
return this.http.delete<Relative>(url).pipe(
tap(rel => console.log( `deleted relative id=${id}`)),
catchError(this.handleError)
);
}
And this is the method i call with the click event in my-profile.component.ts:
delete(id:number): void {
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;
});
That is my-profile.component.html with a ngif to test the presence of the data in db and an ngfor* to create a table with the db data:
<table *ngIf = 'relatives && relatives.length'
class="table" id="myTable" style="margin:20px; width: 90%;border-style: outset">
<thead>
<tr>
<th>Cognome</th>
<th>Nome</th>
<th>Telefono</th>
<th>Relazione</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor ='let rel of relatives'>
<td>{{rel.lastName}}</td>
<!-- <td><input type="text" name="name" [(ngModel)]=rel.lastName></td> -->
<td>{{rel.firstName}}</td>
<td>{{rel.phone}}</td>
<td>{{rel.relationType}}</td>
<td>
<a (click)="delete(rel.relativeId)" ><img src="/Images/elimina.png"/></a>
</td>
<td>
<input class="Caregiver" type="checkbox" value="Caregiver">
<span>Caregiver</span>
</td>
</tr>
</tbody>
</table>
I think can be useful to find help me to find a solution if i post below my app.component.module.ts:
@NgModule({
declarations: [
AppComponent,
WelcomeComponent//,
//CalendarComponent,
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot([
{path: 'home', component: WelcomeComponent},
{path: '', redirectTo:'home',pathMatch:'full'},
{path:'**', redirectTo:'home', pathMatch:'full'}
]),
MyProfileModule,
CalendarModule
],
providers: ,
bootstrap: [AppComponent]
})
export class AppModule { }
If you need some other code from me do not be afraid to ask me.
WebApi work very good so the problem must be in my angular code.
Thanks all!
database angular asp.net-web-api routes http-delete
database angular asp.net-web-api routes http-delete
asked Nov 25 '18 at 20:45
MarcoTheRockMarcoTheRock
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Because you are using *ngFor ='let rel of relatives'
for your <tr>
's all you need to do is remove that deleted data from your relatives
array. This will trigger angular to refresh that component with the new data; removing the deleted item from your table.
To do this, you can use splice
:
relatives.splice(arrayIndex, 1);
so...
delete(id:number): void {
this.relatives.splice(arrayIndex, 1);
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;}
);
}
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471780%2fi-delete-a-datarow-from-my-database-but-not-from-my-webpage-until-i-refresh-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because you are using *ngFor ='let rel of relatives'
for your <tr>
's all you need to do is remove that deleted data from your relatives
array. This will trigger angular to refresh that component with the new data; removing the deleted item from your table.
To do this, you can use splice
:
relatives.splice(arrayIndex, 1);
so...
delete(id:number): void {
this.relatives.splice(arrayIndex, 1);
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;}
);
}
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
add a comment |
Because you are using *ngFor ='let rel of relatives'
for your <tr>
's all you need to do is remove that deleted data from your relatives
array. This will trigger angular to refresh that component with the new data; removing the deleted item from your table.
To do this, you can use splice
:
relatives.splice(arrayIndex, 1);
so...
delete(id:number): void {
this.relatives.splice(arrayIndex, 1);
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;}
);
}
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
add a comment |
Because you are using *ngFor ='let rel of relatives'
for your <tr>
's all you need to do is remove that deleted data from your relatives
array. This will trigger angular to refresh that component with the new data; removing the deleted item from your table.
To do this, you can use splice
:
relatives.splice(arrayIndex, 1);
so...
delete(id:number): void {
this.relatives.splice(arrayIndex, 1);
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;}
);
}
Because you are using *ngFor ='let rel of relatives'
for your <tr>
's all you need to do is remove that deleted data from your relatives
array. This will trigger angular to refresh that component with the new data; removing the deleted item from your table.
To do this, you can use splice
:
relatives.splice(arrayIndex, 1);
so...
delete(id:number): void {
this.relatives.splice(arrayIndex, 1);
this.myProfileService.deleteRelative(id).subscribe(
data=>{this.route;}
);
}
edited Nov 26 '18 at 20:04
answered Nov 25 '18 at 20:50
ZzeZze
10.4k64069
10.4k64069
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
add a comment |
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
this where?thanks
– MarcoTheRock
Nov 26 '18 at 14:34
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
@MarcoTheRock See update.
– Zze
Nov 26 '18 at 20:04
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
it works as before, so the row still remain when i click on the delete button.
– MarcoTheRock
Nov 27 '18 at 9:10
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471780%2fi-delete-a-datarow-from-my-database-but-not-from-my-webpage-until-i-refresh-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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