angular5

How to set header to HttpHeaders in angular 5 [duplicate]

末鹿安然 提交于 2020-06-01 06:16:10
问题 This question already has answers here : Adding a HTTP header to the Angular HttpClient doesn't send the header, why? (8 answers) Interceptor Angular 4.3 - Set multiple headers on the cloned request (4 answers) Closed 2 years ago . I'm trying to figure out how to handle headers on HttpHeaders to use them for http requests via HttpClient. const headers = new HttpHeaders(); headers.append('foo', 'bar'); headers.set('foo', 'bar'); console.log(headers.get('foo')) // null it works only this way:

How I can create Angular custom Date Pipe

烂漫一生 提交于 2020-05-31 04:18:33
问题 I'm working on angular 5 I want to create a costume date pip that allow me to subtract some days from a date : This how I display my date value : <span>{{data.nextCertificateUpdate | date:'yyyy-MM-dd'}}</span> for example this display a value like : 2018-08-29 I ask if it's possible to create a pipe that allow me to substract a number of days for example 28 from this date ? Something like : <span>{{data.nextCertificateUpdate | mypipe:28 }}</span> and this should display value like : 2018-08

File 'src/app/app.component.spec.ts' is not part of Typescript project while upgrading to Angular 5

倖福魔咒の 提交于 2020-05-29 05:32:27
问题 File 'src/app/app.component.spec.ts' is not part of Typescript project 'src/tsconfig.app.json' while upgrading to Angular 5 We have followed all the instructions for converting our project from angular 4 but are pulling out our hair over this one - anyone have any ideas? We are getting this error from tslint... 回答1: Change the "lint" section of .angular-cli.json by replacing all of the "files" entries with "exclude" entries... "lint": [ { "project": "src/tsconfig.app.json", "files": "src/**/*

angular templateRef nativeElement is an empty comment instead of original element

一世执手 提交于 2020-05-29 03:56:06
问题 I am developing an angular directive that converts dropdownlist to radioListbox. here is my initial code : import { Directive, Input, TemplateRef, ViewContainerRef,OnInit } from '@angular/core'; @Directive({ selector: '[radioList]' }) export class RadioListDirective implements OnInit { constructor(private templateRef: TemplateRef<any>, private vcRef: ViewContainerRef) { } ngOnInit() { console.log(this.templateRef); this.vcRef.createEmbeddedView(this.templateRef); } } and <div> test </div>

Problems with flask and bad request

给你一囗甜甜゛ 提交于 2020-05-25 17:18:52
问题 I was programming myself a pretty nice api to get some json data from my gameserver to my webspace using json, but everytime i am sending a request using angular i am getting this: 127.0.0.1 - - [20/Mar/2018 17:07:33] code 400, message Bad request version ("▒\x9c▒▒{▒'\x12\x99▒▒▒\xadH\x00\x00\x14▒+▒/▒,▒0▒\x13▒\x14\x00/\x005\x00") 127.0.0.1 - - [20/Mar/2018 17:07:33] "▒\x9dtTc▒\x93▒4▒M▒▒▒▒▒\x9c▒▒{▒'\x99▒▒▒▒H▒+▒/▒,▒0▒▒/5" HTTPStatus.BAD_REQUEST - 127.0.0.1 - - [20/Mar/2018 17:07:33] code 400,

Angular 5 custom input pipe loses focus when deleting charcter

允我心安 提交于 2020-05-17 07:45:11
问题 I have an input in with a custom pipe that adds a space every 4 characters inserted. The issue is that if I insert for example "1234 5678" and I go and delete 4, the focus instead of staying there to insert a new character it moves to the end. PIPE import { Pipe, PipeTransform } from "@angular/core"; @Pipe({ name: 'formatBankAcc' }) export class FormatBankAccPipe implements PipeTransform { transform(value: string) { if (value != null) { value = value.replace(/[^\dA-Z]/g, '') .replace(/(.{4})

Route to Same component with multiple Params

余生长醉 提交于 2020-05-16 20:11:52
问题 HTML Code <button (click)='getEnv("env")'>environment</button> <button (click)='getSchema("env","schema")'>schema</button> <button (click)='getEvent("env","schema","event")'>event</button> ROUTE FILE export const ROUTES: Routes = [ { path: '', redirectTo: 'home',pathMatch:"full" }, //{ path: 'home', component: HomeComponent }, { path: 'example', component: ExampleComponent }, { path: '**', component: HomeComponent }, { path: 'home/:env', component: HomeComponent,pathMatch:'full' }, { path:

Angular Material Modules are not recognized

放肆的年华 提交于 2020-05-16 03:57:26
问题 I wasted a lot of time on this mistake, I'm starting new angular5 project and I want to use angular material. I imported and exported the material modules in a material.module.ts file: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { CommonModule } from '@angular/common'; import { MatIconModule,MatButtonModule,MatSidenavModule,MatToolbarModule } from '@angular/material'; @NgModule({ imports: [ BrowserModule, CommonModule,

Cannot enable prod mode after setup

倾然丶 夕夏残阳落幕 提交于 2020-05-15 06:47:13
问题 When I try to enable prod mode in my Stack Blitz it sometimes tells me Cannot enable prod mode after setup https://stackblitz.com/edit/angular-gitter-fv1bhs 回答1: That's because of HMR. It doesn't reload the window so the old platform instance is still there, so it tries to reinitalize the new instance but the old one is like "nope, we already started" So the answer is basically to close/open the preview window. I hope it works ;D 来源: https://stackoverflow.com/questions/47983242/cannot-enable

Angular5 PWA doesn't refresh (Service Workers)

一世执手 提交于 2020-05-15 04:46:25
问题 I'm developing an app with angular5, using service workers via the ng-cli, but I realized that after the first time the app shell loads, it doesn't refresh. How can I push new file versions to my app after build it with ng build ?. I could directly rewrite the sw.js manually, but as it is generated via the cli, I don't like to affect anything I don't know what is for. I'm looking for this answer all day, but as service workers are new for the 1.6 version of the ng-cli, I have not found any. I