TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sonal malhotra
NA
410
52k
error(blogservice) in angular with web api please solve
Jul 4 2019 5:29 AM
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<Iblog> {
let headers =
new
Headers({
'Content-Type'
:
'application/json'
});
let options =
new
RequestOptions({ headers: headers });
return
this
._http.
get
(url + id, options)
.map((response: Response) => <Iblog>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 Details
</
h2
>
<
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']"
>
Back
</
a
>
</
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
Reply
Answers (
2
)
Routing in Angular
hosting support angular & api free