angular2-services

Property 'subscribe' does not exist on type '() => Observable<any>'

两盒软妹~` 提交于 2019-12-30 01:51:11
问题 service file import { Observable } from 'rxjs/Rx'; import { Http,Response} from '@angular/http'; import { Injectable } from '@angular/core'; import 'rxjs/add/operator/Map'; @Injectable() export class VideoService { private geturl = '/api/videos'; constructor(private _http:Http) { } getvideos() { return this._http.get(this.geturl).map((response:Response) => { response.json() }); } } here is where the subscribe method showing this error import { VideoService } from '../video.service'; import {

how to read http status code error in component

纵饮孤独 提交于 2019-12-29 01:26:26
问题 I know this has been asked before but I can't seem to find the answer, how to read status code from http..? this.bookingService.save(this.param) .subscribe( data => swal({ "title": "Succes!", "text": "Your data saved", "type": "success", "confirmButtonClass": "btn btn-secondary m-btn m-btn--wide" }), error => console.log('error'), () => this.router.navigate('Succes') ); 回答1: You can get the status code from the error, this.bookingService.save(this.param).subscribe( data =>{ console.log(data);

Can lazy-loaded modules share the same instance of a service provided by their parent?

萝らか妹 提交于 2019-12-28 01:55:09
问题 I've just run into a problem with a lazy-loaded module where parent and child module both require the same service but create an instance each. The declaration is identical for both, that is import { MyService } from './my.service'; ... @NgModule({ ... providers: [ MyService, ... ] }); and here's the routing setup export parentRoutes: Routes = [ { path: ':id', component: ParentComponent, children: [ { path: '', component: ParentDetailsComponent }, { path: 'child', loadChildren: 'app/child

angular2 router become undefined in subscribe method

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:41:13
问题 As the title explains it, the router object become undefined when it's called inside a subscribe member. Let me show you some code: export class AuthComponent implements OnInit { password = ''; email = ''; constructor( private _router: Router, private authService: AuthService ) { } sendLogin(): void { this.authService.login(this.email, this.password) .subscribe(function(token){ console.log("Success Response" + token) this.token = token // TOKEN Here is good // now I want to change my page,

How to provide a router navigate function in Angular 2 project

耗尽温柔 提交于 2019-12-25 07:26:28
问题 In my Angular 2 project I have a custom function goToObject(objectType:string, objectID: number) that I use to navigate to different objects throughout a couple of different components in my application. The function looks as follows: goToObject(objectType:string, objectID: number) { this._router.navigate([type, id]); } I was wondering if there is a way to provide this function throughout my complete project, without having to define it in each component separately. What makes it harder I

Self referencing loop Detected for property in Asp.net MVC with Angular 2

℡╲_俬逩灬. 提交于 2019-12-24 19:44:19
问题 I Have Create a DB in that I am Having Multiple tables having Relationship between them. When a try to get data from my WEb app i get this error "'Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.PrescriptionMaster_2C4C63F6E22DFF8E29DCAC8D06EBAE038831B58747056064834E80E41B5C4E4A'. Path '[0].Patient.PrescriptionMasters" I coudn't get why i am getting this error, and when i remove the relationships between tables i get proper data From it. I have Tried other solutions

How to manage the roles and permission in angular 2

非 Y 不嫁゛ 提交于 2019-12-24 19:23:15
问题 Hi I have stored the below data "permission": { "1000": "CREATE_DISBMT_WORKFLOW", "1001": "EDIT_DISBMT_WORKFLOW", "1002": "EDIT_UPLOAD_PHOTO_DISBMT_WORKFLOW", "1003": "EDIT_UPLOAD_CONFIRMED_DISBMT_WORKFLOW", "1004": "EDIT_VERIFIED_DISBMT_WORKFLOW", "1005": "VIEW_DISBMT_WORKFLOW", "1006": "DELETE_DISBMT_WORKFLOW" } in local storage now I want to create a function on which I will pass CREATE_DISBMT_WORKFLOW if it's there in above permission object that it should return true else false what is

Is it possible to have multiple level Nested Route in Angular2

好久不见. 提交于 2019-12-24 16:40:34
问题 Is it possible to have multiple level nesting for angular routing. I am trying to achieve below but it says [Child routes are not allowed for "/cash/..". Use "..." on the parent's route path]. Intended route /storeselector /forms - shows all forms /forms/cash/ - user select cash form from list of forms and on load it will shows all orders /forms/cash/id:1/ shows order details /forms/cash/edit/1 edit order 1 below is my code. app component @Component({ selector : 'forms-app', templateUrl :

Angular 2 - find instance in array

ぃ、小莉子 提交于 2019-12-24 09:54:20
问题 Im building a dummy login for an app, and I need to check for an instance of the user logging in, within an array I have some mock data import { User } from './user'; export const USERS: User[] = [ {username: 'Seth', password: 'youwillneverknow'}, {username: 'Peter', password: 'iforgot'}, {username: 'Frank', password: 'test123'}, ]; Which I use in my user.service file import { Injectable } from '@angular/core'; import { User } from './user'; import { USERS } from './users.mock'; @Injectable()

Angular 2 - Wait for data init from service

拈花ヽ惹草 提交于 2019-12-24 09:35:25
问题 There are 2 services: DataService - gets data from the server CacheService - subscribes to DataService and holds mapped data and component ComponentA - Injects CacheService and has foo function that handles cached data My question is - How do I ensure that my CacheService is done with data when my foo function gets called . Current solution that I kinda like but am not sure if there isn't some better Angular 2 way. Done with Rx.Observables My solution (Code is simplified): export class