angular2-services

Need to access service in function

坚强是说给别人听的谎言 提交于 2021-02-20 18:43:35
问题 I have a service (AuthService) that I need to access in my restangularInit function (in my app.module.ts) but I don't know how, I can't get access to it. I have tried to move it to the class AppModule but by then it´s to late. Calling the service functions eg. getToken works as expected. import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import {

ng build command is not working via jenkins build execute shell

大城市里の小女人 提交于 2021-02-10 18:38:18
问题 In jenkins build execute area I put these command: cd /var/lib/jenkins/workspace/test/ ng serve Here is the screenshot: I am getting an error like this: cd /var/lib/jenkins/workspace/test/ ng serve Environment variable TERM not defined! Build step 'Execute shell' marked build as failure Finished: FAILURE node v6.10.0 @angular/cli: 1.0.6 Please help me to resolve this issue. 回答1: Try this I did jenkins integration today. npm run ng build This is working fine. 回答2: In my case my slave Jenkins

cyclic dependency error when importing service into another service

人盡茶涼 提交于 2021-01-28 05:33:04
问题 I'm trying to set default headers for my http requests using the DefaultRequestOptions class provided by Angular 2. Documentation can be found here: https://angular.io/docs/ts/latest/guide/server-communication.html#!#override-default-request-options I want to add a default bearer token, which gets set in one of my services, but doing so gives me the following error in my browser console: Unhandled Promise rejection: Provider parse errors: Cannot instantiate cyclic dependency! Http: in

Typescript - Declare optional global variable

非 Y 不嫁゛ 提交于 2021-01-27 08:04:39
问题 I am creating a service to check if a user is logged in. This will just be a global variable 'userIsLoggedIn' which is passed from the backend. This service will be used across several applications and sometimes the userIsLoggedIn global variable will not exist. What I have is... import { Injectable } from '@angular/core'; declare const userIsLoggedIn: boolean; @Injectable() export class UserLoggedInService{ isUserLoggedIn(): boolean { return userIsLoggedIn || false; } } If the userIsLoggedIn

Typescript - Declare optional global variable

怎甘沉沦 提交于 2021-01-27 08:03:16
问题 I am creating a service to check if a user is logged in. This will just be a global variable 'userIsLoggedIn' which is passed from the backend. This service will be used across several applications and sometimes the userIsLoggedIn global variable will not exist. What I have is... import { Injectable } from '@angular/core'; declare const userIsLoggedIn: boolean; @Injectable() export class UserLoggedInService{ isUserLoggedIn(): boolean { return userIsLoggedIn || false; } } If the userIsLoggedIn