hello expert,
i m sharing coding in angular in web api method code are here ..
- public HttpResponseMessage GetId(string id)
- {
- //blogtaable objEmp = new blogtaable();
- int ID = Convert.ToInt32(id);
- angDB.blogtaables.Where(x => x.blogid == ID).Single();
- return ToJson(angDB.SaveChanges());
- }
i am not sure is this correct ? i want to display blog details in webapi controller
how to write syntax/code in web api method(GetId)?
here is blogservice
- Getid(url: string, id: any): Observable
{ - let headers = new Headers({ 'Content-Type': 'application/json' });
- let options = new RequestOptions({ headers: headers });
- return this._http.get(url + id, options)
- .map((response: Response) =>
response.json()) - .catch(this.handleError);
Error is shown in blog service
here is blog details .ts
- import { Component, OnInit } from '@angular/core';
- import { RouterModule, ActivatedRoute } from '@angular/router';
- import { blogService } from '../Service/blogservice';
- import { Observable } from 'rxjs/Observable';
- import { Iblog } from '../model/blog';
- import { Global } from '../Shared/global';
- @Component({
- selector: 'employee-details',
- templateUrl: 'app/components/blog-details.component.html',
- providers: [blogService],
- })
- export class blogDetailsComponent implements OnInit {
- private sub: any;
- private blog: Iblog;
- constructor(private employeeService: blogService, private route: ActivatedRoute) {
- }
- ngOnInit() {
- // Subscribe to route params
- this.sub = this.route.params.subscribe(params => {
- let id = params['id'];
- return this.employeeService.Getid(Global.BASE_USER_ENDPOINT,id).subscribe((blogs1 => { this.blog = blogs1; }));
- });
- }
- }
here is blog details in html
- <div *ngIf="blog">
- <h2>Blog Detailsh2>
- <table>
- <tr>
- <td>Title:td>
- <td>{{blog.Title}}td>
- tr>
- <tr>
- <td>Date:td>
- <td>{{blog.dateofpublish}}td>
- tr>
- <tr>
- <td>content:td>
- <td>{{blog.content1}}td>
- tr>
- table>
- <a [routerLink]="['/blogs']">Backa>
- div>
here is routing..
- import { ModuleWithProviders } from '@angular/core';
- import { Routes, RouterModule } from '@angular/router';
- import { blogComponent } from './components/blog';
- import { HomeComponent } from './components/home';
- import { blogDetailsComponent} from './components/blog-details.components';
- const appRoutes: Routes = [
- { path: '', redirectTo: 'home', pathMatch: 'full' },
- { path: 'home', component: HomeComponent },
- { path: 'blog', component: blogComponent },
- { path: 'blog/:id', component: blogDetailsComponent },
- ];
- export const routing: ModuleWithProviders =
- RouterModule.forRoot(appRoutes);
please share idea for error .. if i did wrong something then please share ur code or repair
Veerendra AnnigerePosted Jul 6, 2019, 10:06 PM
Sivakumar KonetiPosted Jul 4, 2019, 11:33 PM