angular6

RXJS 6: new version of HttpInterceptor

笑着哭i 提交于 2019-11-29 12:39:56
问题 I am in the process of adding rxjs_compat to my project in order to move to v6 of libraries. However the existing HttpInterceptor for global error handling no longer compiles. Not sure where to go with it. Tried all sorts. Getting type mismatches with everything tried. import { Injectable } from "@angular/core"; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse } from "@angular/common/http"; import { Observable, of, empty } from "rxjs"; import {

Property 'from' does not exist on type 'typeof Observable', angular 6?

核能气质少年 提交于 2019-11-29 11:01:47
I updated my angular 5.2.10 project to angular 6. I did step by step https://update.angular.io/ , everything is OK unless Observable.from In a service I used Observable.from(this.user) as following: import { Observable } from 'rxjs/Observable'; ... Observable.from(this.users)// this.users is an array It was OK, but in angular 6 the following error occurred Property 'from' does not exist on type 'typeof Observable' I changed it as follows import { Observable, from } from 'rxjs'; But no change and error occurred again! In rxjs@6 you can use from as standalone function: import { from } from 'rxjs

In Angular 6 how make case insensitive url pattern?

空扰寡人 提交于 2019-11-29 10:23:12
In my case I want to support same url in case insensitive manner. Example: it should support all url localhost:1029/documentation localhost:1029/DOCUMENTATION localhost:1029/DOCUMENTAtion localhost:1029/docuMENTATION mittal bhatt You should add this provide statement to the app.module.ts import { DefaultUrlSerializer, UrlTree } from '@angular/router'; export class LowerCaseUrlSerializer extends DefaultUrlSerializer { parse(url: string): UrlTree { // Optional Step: Do some stuff with the url if needed. // If you lower it in the optional step // you don't need to use "toLowerCase" // when you

Angular 6, should I put secret environment variables in environment.ts file?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 07:24:29
问题 There are two sub-questions: Should I put secret environment variables in environment.ts file? The process variable shim is gone. If I use it, tsc will throw an error: Cannot find name 'process' . Here is my thing: About Q1: I don't think put secret environment variables in environment.ts file is correct. Because these files will be a push to source code management, like GitHub, gitlab, bitbucket. It's not safe. So I think secret environment variables should be passed through process.env ,

Multiple application under single project in Angular 6

匆匆过客 提交于 2019-11-29 06:24:33
问题 How to create multiple application under single project in Angular 6? In new angular.json file, there is no "app":[] array, where before we used to create/add multiple applications manually. Also there is no proper documentation I found at this stage, which elaborate how to create multiple application in single project. Any help would be appreciated. Thank you. 回答1: Like @JB Nizet said... you can use generate application (https://github.com/angular/angular-cli/wiki/generate-application) ng

Update to Angular v6 - Module not found: Error: Can't resolve 'fs'

天大地大妈咪最大 提交于 2019-11-29 06:11:04
I'm trying to migrate my Angular Universal project from Angular v5 to v6 I've got a service where I use fs to load the translation on the server side. Everything works well with Angular v5. With Angular v6, when I run npm run start aka ng serve --proxy-config proxy.conf.json I face the following error ERROR in ./src/providers/core/translate/translate-universal-loader.service.ts Module not found: Error: Can't resolve 'fs' in '/Users/me/Documents/projects/myproject/src/providers/core/translate' In my service I declare fs like the following: declare var require: any; const fs = require('fs'); I

Angular 6 - run method is service every 10 seconds

谁说胖子不能爱 提交于 2019-11-29 02:24:17
I have this service using HttpClient to get some data : checkData() { return this.http.get('my url'); } The on the footer component I call it and display the result : ngOnInit() { this.myservice.checkdata().subscribe( result => { this.statustext = result } ); } This works, but I need this method to be run every 10 seconds so it's up to date. How can I do this? Faisal Use rxjs timer to call the api request at startup and then every 10s. This is best achieved by using rxjs to divide and conquer. Firstly, import the following: import { timer, Observable, Subject } from 'rxjs'; import { switchMap,

Angular 6: Property 'catch' does not exist on type 'Observable<Response>'?

本秂侑毒 提交于 2019-11-29 01:23:48
I am upgrading my app to Angular 6 . I am upgrading from Angular 4 , but the code below is causing errors in Angular 6, where it worked fine in Angular 4. The errors I am getting: Property 'of' does not exist on type 'typeof Observable' Error: Property 'catch' does not exist on type 'Observable' How should I resolve these errors? private authInterceptor(observable: Observable<Response>): Observable<Response> { return observable.catch((error, source) => { if (error.status == 401) { this.router.navigateByUrl('/login'); return Observable.of(); } else { return Observable.throw(error); } }); }

How to add/set environment Angular 6 angular.json file

耗尽温柔 提交于 2019-11-29 00:20:28
问题 How to I specify the environment to use in Angular 6? The .angular-cli.json file seems to have changed to angular.json from previous versions and with it the structure of the json within. How/where in this file do I specify the environments to use? 回答1: Open angular.json file. we can see the configurations by default it will be shown for production add code snippet for your respective environments. add environment.dev.ts file in environment for dev, add environment.qa.ts for qa. Name as you

Cannot find module 'webpack' - Angular

喜欢而已 提交于 2019-11-28 21:19:47
I just migrated my project from angular v5.x to v6.x and now when I try to start it with ng serve I'm getting: Cannot find module 'webpack' Error: Cannot find module 'webpack' at Function.Module.... any help ? I cleared node modules and: npm cache clean --force npm install npm install --save-dev @angular/cli@latest but that didn't help Tristan mariën I had the same issue and this worked for me: Delete these files/ folders (from your Angular root folder): package-lock.json ( Not the package.json) /node_modules folder /dist folder Execute command (regenerate the package-lock.json and the /node