angular2-services

Redirect to Previous Page In Angular

时光毁灭记忆、已成空白 提交于 2019-12-04 20:00:46
I have installed a package called ngx-pagination. But i have a problem since when you navigate away from the previous page and you click the back button, it redirects you to the first page instead of going back to the previous page? How can i make it return to the previous page if i click the back button in the browser? Here's my code below. TS config: any; constructor() { this.config = { currentPage: 1, itemsPerPage: 2 }; this.route.paramMap .map(params => params.get('page')) .subscribe(page => this.config.currentPage = page); } } ngOnInit() { this.getAllBooks(); } pageChange(newPage: number)

How exactly works the services hierarchy in this Angular 2 application?

心已入冬 提交于 2019-12-04 19:17:08
I am very new in Angular 2 and I have the following question about services . Into the main view (the one related to the app.component.ts class) I have this situation: <div class="container"> <div class="row"> <div class="col-xs-12 col-md-8 col-md-offset-2"> <app-new-account (accountAdded)="onAccountAdded($event)"></app-new-account> <hr> <app-account *ngFor="let acc of accounts; let i = index" [account]="acc" [id]="i" (statusChanged)="onStatusChanged($event)"></app-account> </div> </div> </div> So into this view I have 2 sub component ( app-new-account and app-account ). Into the main

Angular 2 Service… Pointless?

无人久伴 提交于 2019-12-04 17:10:32
I have been using angular 2 for about 2 weeks now and I love it with the exception of one thing... Services. Despite using them, to conform to society, I don't understand the point and I hope some one can explain the reasoning. Services don't do anything besides load data. Not to mention 9/10 what ever component I inject it into has to have similar functions to handle the data returned and make it usable. Another big problem I have with them is the overhead. Lets say (Following the heroes tutorial) I run an ajax request (using the service) to create a list of heroes, I click on one and now I

Compile Angular 2 node_modules files into one file

拥有回忆 提交于 2019-12-04 15:08:06
I am trying to figure out a way to compile everything I need from the angular 2 node_modules folder into one file.. It seems that there is a crazy amount of http calls when my site is loading and surely thats not optimal or the recommended process of the new and improved angular.. Im not concerned with my own typescript files as i know how to handle them but what are your approaches to concatenating the node_modules files etc ? If you're using SystemJS 1. package.json : add these to devDependencies "devDependencies": { "gulp": "^3.9.1", "systemjs-builder": "^0.15.16" } 2. do npm install 3.

How do I add a json web token to each header?

北城以北 提交于 2019-12-04 11:15:56
问题 So I am trying to use JSON web tokens for authentication and am struggling trying to figure out how to attach them to a header and send them on a request. I was trying to use https://github.com/auth0/angular2-jwt but I could not get it working with Angular and gave up, and figured I could just figure out how to either send the JWT in every request or send it in the header(preferably the header). It's just been a little bit harder than I thought it would be. Here is my Login submitLogin

Angular 2 service not being injected into component

风格不统一 提交于 2019-12-04 11:09:09
I have a service defined in my Angular2 (2.0.0-beta.0) application. It's something like this: import {Injectable} from "angular2/core"; @Injectable() export class MyService { constructor() { } getSomething() { return 'something'; } } I have it listed in my bootstrap() function in my main app file so that it should be made available to my code in general: bootstrap(App, [MyService, SomeOtherService, ROUTER_DIRECTIVES[); Sometimes I can't use the service in a component, even though I have something like myService:MyService in the component constructor() function, like this: import {MyService}

Angular 2 share websocket service across components

社会主义新天地 提交于 2019-12-04 07:21:12
I am building a web application using angular 2 in which I want to have multiple components listening to the same service. This service returns an observable that returns incoming data from a websocket. I wrote the code based on this example. The current problem is: The data is send from the home component through the service to the server (using websockets) and data is returned. However, only the observer in the home.component is getting called (with id: room.created and data), not the one in the navbar. Could someone tell me why not both are called? I also tried to add the messages$

Angular 2 get routeParams in a service

醉酒当歌 提交于 2019-12-04 06:05:40
I want to shift the logic from component to service. But I found out that I can't get the routeParams in a service. My component looks like import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; import { MyService } from '../services/my.service'; @Component({ moduleId: module.id, templateUrl: 'my.component.html', styleUrls: ['my.component.css'] }) export class MyComponent implements OnInit { constructor(private myService: MyService, private route: ActivatedRoute) {;} public ngOnInit() { this.route.params .subscribe((params: Params) => {

Angular2: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined

混江龙づ霸主 提交于 2019-12-04 04:15:48
I'm new to observables and experimenting with an basic autocomplete variation of Christoph Burgdorf's Observables in Angular2 blog . Running this code produces: EXCEPTION: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined after issuing the REST get call in ingredientservice...rawsearch. The alert also pops with an [object Object] message. I've verified the endpoint is running fine. Any recommendations on how to debug this would be greatly appreciated. ingredientservice.ts waits for a change on a text string, debounces it and performs a REST call to get autocomplete matches

Calling Angular2SocialLoginModule function calls not supported

孤人 提交于 2019-12-04 04:10:19
问题 I am new to angular js2. Currently I am working with a web application, which uses angular2 for front-end. In this application I have used angular2-social-login for authentication purpose. But when I run the npm start I got the below error ERROR in Error encountered resolving symbol values statically. Calling function 'Angular2SocialLoginModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in