angular2-services

Best way to wait for 3rd-party JS library to finish initializing within Angular 2 service?

时间秒杀一切 提交于 2019-12-13 15:26:40
问题 I'm wrapping a 3rd-party JS library in an Angular service. How can I guarantee that the 3rd-party JS library is loaded/initialized/etc. before using my service? Can you take a look at the following code and tell me if this is a good coding practice ? I'm setting up a promise in the service's constructor (promise that will eventually be fulfilled) and I have the service methods depend on the success of that promise (see getMessages ). @Injectable() export class GmailService { private

ANGULAR 2 - Component Shared Data Service

断了今生、忘了曾经 提交于 2019-12-13 15:13:39
问题 this has really been wreaking my head. I have a nice little app with social login setup using Firebase and Angular 2. Everything should be realtime. Basically when a user logs in via Facebook I want their personal info to be passed to a service and stored as an Observable and display instantly in any component that subscribes to the service, I then want to be able to access this Observable from within Components that are not directly linked to each other and may even be totally out of the

Parse information from a Hal+JSON object in Angular 2

家住魔仙堡 提交于 2019-12-13 13:27:57
问题 I have a spring-data-rest repository producing a hal+json object that I'd like my Angular 2 front end to receive and display. Hal+Json Object: { "_embedded" : { "users" : [ { "name" : "Bob", "_links" : { "self" : { "href" : "http://localhost:4200/api/users/1" }, "user" : { "href" : "http://localhost:4200/api/users/1" } } }, { "name" : "Joe", "_links" : { "self" : { "href" : "http://localhost:4200/api/users/2" }, "user" : { "href" : "http://localhost:4200/api/users/2" } } } ] }, "_links" : {

How to connect Angular 2 with MySql Database using Nodejs?

心不动则不痛 提交于 2019-12-13 09:01:42
问题 I started new project for Retail Shop, I need to connect Angular 2/5 with MySQL Database using Node or any other method. I need Examples for Select, Create, Delete, Update. for now i need to create Login Page. 回答1: Well connecting Angular??? First learn that Angular, front end, does never connect to any database directly (not counting a New England db or LocalStorage as Database). You need node or any other server side technology and then serve a REST API for providing data to your front end

Invalid provider Error while consuming webapi using http provider

☆樱花仙子☆ 提交于 2019-12-13 07:19:30
问题 I am trying to consume a webapi service in angular2/http component. For learning purpose I want to consume the public restapi service which returns the list of countries. I have written a angular2 component which would invoke the CountryService component to consume the actual restapi service and then iterate the list and dispaly to the user. I have created a plunkr for testing this. Plunker URL. I am running into a issue like below in the chrome browser angular2.dev.js:24821 Error: Uncaught

Angular2/4 post method not working

天大地大妈咪最大 提交于 2019-12-13 04:43:32
问题 I am new in angular2/ 4 web api. I want to save some data to database using angular 4 web api http. When i call a GET method from angular it works fine, but not working on POST method. I am getting 415 Unsupported Media Type.All the time, but when I use postman the post method is work fine because I change the content type to application/json. when i use alert button i get [object,Object],But in angular2/4 it's not working... I see lots of issues with the same problem, but they don't work for

Ruler service not working as local dependency

孤街醉人 提交于 2019-12-13 02:18:48
问题 I based my code using this plunker: http://plnkr.co/edit/81nWDyreYMzkunihfRgX?p=preview As you can see is loading dependencies remotely (scripts with http/s), then I change them using node and replacing all dependencies locally with a package.json and tsconfig.json. However, when changing the ruler and rectangle dependencies to local like this: import {Ruler, Rectangle} from "angular2/src/platform/browser/ruler"; Appears an error saying: "SyntaxError: expected expression, got '<' Evaluating

How to get new instance/reload all services on logout in Angular2

好久不见. 提交于 2019-12-12 18:26:53
问题 I am developing angular2 application which is similar to Plunkr link provided at the end. In HeroService i have an property clickCount, which will be incremented on click of hero. But After login i want to reset this parameter. I don't want to use the service and reset its value (actually in my application i am using many services, so cannot use each service and reset its value on logout). Is there any method to reset/reload service on particular action without reloading entire application.

Angular2 Property does not exist on type

∥☆過路亽.° 提交于 2019-12-12 15:18:48
问题 I am trying to get my connected user model after login process, First the user is redirecting to "/login" URL after CanActivate guard checked the local storage with the user JSON object and found that it is null Then the user is logging in and redirect back to root URL "/", on the connecting process I'm using AuthService that save the user object that returned from the server in a user model but i'm getting this error: src/app/_guards/auth.guard.ts (12,48): Property 'token' does not exist on

Angular 2 - Http - Properly Ignore Empty Results

无人久伴 提交于 2019-12-12 14:16:49
问题 I have quite a few REST end-points that process a request and simply return 200. I noticed it is an error to map the result with json() . If I try not to do any sort of mapping whatsoever, I see a browser warning that it could not parse XML. As returning nothing is pretty common, I am curious how I should be handling the response. Here is a basic code example: await this.http.put("/api/some_url", data).toPromise(); Here is the warning that shows up in Firefox: XML Parsing Error: no root