angular2-services

Error while using the Auth0 spa quickstart

我与影子孤独终老i 提交于 2019-12-10 13:15:26
问题 I'm currently working on an Angular 2 web app that will use Auth0 for user authentication. I followed the quickstart at the Auth0 website, but I'm getting the error Cannot read property 'WebAuth' of undefined at new AuthService (auth.service.ts:9) , even though AuthService is declared. Am I missing something? Any help is very much appreciated. This is my code //app.component.ts import { Component } from '@angular/core'; import { AuthService } from '../../auth/auth.service'; @Component({

How do you inject a custom service into another custom service?

佐手、 提交于 2019-12-10 12:42:41
问题 I'm getting a No Provider for FirebaseService error even after bootstrapping the FirebaseService in the bootstrap(app, [providers]) method. I followed Pascal's guide for injecting a service within a service and it worked when I injected the Http service with the HTTP_PROVIDERS bootstrapped, but I receive a No providers for FirebaseService error after changing it to my own service. I can inject both providers individually by removing the injection of the FirebaseService just fine. Even if I do

storing json data from a file in local variable

只谈情不闲聊 提交于 2019-12-10 12:09:00
问题 I want to load data from a local .json file and store the content in a local variable, that is accessible throughout the program. I have this function inside my service which I call to get the data. GetData(){ this.d={Data:[],number:[]} this.http.get('data.json').map(res =>res.json()).subscribe(res=> {this.d=(res); console.log(this.d); //this.d gets the value from res and prints the expected value }); console.log(this.d);//this.d gets printed as empty return this.d; } this.d seems to get the

Excel upload using Angular2(Frontend) and Springboot (Backend)

梦想的初衷 提交于 2019-12-10 11:47:59
问题 Hi I am new to angular2 and I am trying to upload an excel from an angular2 frontend .What exactly I want to achieve is , upload the excel from angular2 frontend pass it to Springboot in backend ,inside springboot I will make necessary changes .Finally pass it back to angular to render it on screen . My Approach : let user select the excel from frontend POST it to springboot backend , make necessary modification using apache POI Finally pass it to angular again to render it on screen .

Communication between angular 2 and pure javascript

大城市里の小女人 提交于 2019-12-10 11:44:05
问题 I am building an angular application and i am in a situation where i have to communicate with an external javascript. Scenario During app initialization, i inject two iframes into index.html using document.body.appendChild(iframe); I have script running in index.html and has a multiple functions among which one is getData(); I have to send data to this function from the angular app component when the app initialises. How to go about this ? I know how to communicate from javascript to angular

How to get once instance of service with Inject

孤人 提交于 2019-12-10 11:26:36
问题 How can I get the same once instance of singleton service using Injector: I define provider of this service on the bootstrap application(for one instance on the all application) Example: Bootstrap application //Init application bootstrap(AppComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS, SessionService]); SessionService Singleton - this is just example, but in real can be session or acl service @Injectable() export class SessionService { constructor() { console.warn("INSTANCE OF SESSION SERVICE

Angular 2 - Consuming restful api calls with windows authentication

僤鯓⒐⒋嵵緔 提交于 2019-12-10 11:13:02
问题 I have a .net web api hosted on IIS 7 on a remote server which uses windows authentication. I want to access the web api using Angular 2 using TypeScript with node . Earlier i was getting an error 'Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource' I added this on the hosted Application's web.config <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> But

Angular 2 Subscribe / Unsubscribe Observables in case of http calls

不羁岁月 提交于 2019-12-10 10:48:10
问题 I recently came to know that we must unsubscribe the subscription before Angular destroys the component, and failure to do so could create a memory leak. I also know that we can get a reference to the subscription and by calling unsubscribe method on that subscription we can subscribe. For example private sub: any; ngOnInit() { this.sub = this.route.params.subscribe(params => { let id = +params['id']; // (+) converts string 'id' to a number this.service.getHero(id).then(hero => this.hero =

Angular2 viewContainerRef.createComponent work correctly

若如初见. 提交于 2019-12-10 10:29:03
问题 i used viewContainerRef.createComponent to load dynamic component into root component(.....) ,but actual it append the wrong place, my code: -----app.compoment.ts----- export class AppComponent { private viewContainerRef:ViewContainerRef; public constructor(viewContainerRef:ViewContainerRef) { this.viewContainerRef = viewContainerRef; } } -----a.service.ts------ @Injectable() export class ModalService { private viewContainerRef:ViewContainerRef; constructor(applicationRef: ApplicationRef,

Using Angular 2 focus on next input field with enter key press

≯℡__Kan透↙ 提交于 2019-12-10 08:17:25
问题 I am new in angular 2. How can I move focus to next control on key enter in Angular 2. I implement this code but how not working properly. Please suggest me how I do this. Thanks My component code import { Component,Injectable,Inject,OnInit, OnDestroy, EventEmitter, Output, Directive, ElementRef, HostListener, Input, Renderer } from '@angular/core'; import {Http, Response} from '@angular/http'; import {TestService} from '../../services/test.service'; import 'rxjs/add/operator/map'; import