angular6

The NPM script 'start' exited without indicating that the Angular CLI was listening for requests

我们两清 提交于 2019-11-27 15:28:30
问题 I'm attempting to start an .NET Core 2/Angular 6 SPA. I created an Angular 5 Application using "dotnet new angular" then proceeded to upgrade using this guide from angular.io. Once I finished the upgrade I tried to run the application using "dotnet run" and I get an ugly error page with the error: An unhandled exception occurred while processing the request. AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that

Angular 6 - httpClient passing basic auth in httpOptions

限于喜欢 提交于 2019-11-27 14:59:11
问题 I have a service in Angular 6 and I'm trying to change a record but it's saying I'm not authorized. Right now I have this: const httpOptions = { headers: new HttpHeaders({'Content-Type': 'application/json'}) }; update(id, title, content) { const updateData = { id: id, title: title, content: content }; return this.http.put(`http://myurl/${id}`, updateData, httpOptions); } My question is: How to I add basic authorization to my httpOptions or do I add it direct to the update method? 回答1: You can

Converting httpClient answer to model objects [Angular 6]

你离开我真会死。 提交于 2019-11-27 14:48:56
问题 I have a question about the Angular 5 httpClient. This is a model class with a method foo() I'd like to receive from the server export class MyClass implements Deserializable{ id: number; title: string; deserialize(input: any) { Object.assign(this, input); return this; } foo(): string { // return "some string conversion" with this.title } } This is my service requesting it: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable }

Http post and get request in angular 6

荒凉一梦 提交于 2019-11-27 12:06:05
问题 In angular 5.2.x for http get and post I had this code: post(url: string, model: any): Observable<boolean> { return this.http.post(url, model) .map(response => response) .do(data => console.log(url + ': ' + JSON.stringify(data))) .catch(err => this.handleError(err)); } get(url: string): Observable<any> { return this.http.get(url) .map(response => response) .do(data => console.log(url + ': ' + JSON.stringify(data)) ) .catch((error: any) => Observable.throw(this.handleError(error))); } In

Angular 6 Material mat-select change method removed

偶尔善良 提交于 2019-11-27 11:02:21
问题 In Angular Material Design 6, the (change) method was removed. I cant find how to replace the change method to execute code in the component when the user change selection Thanks! 回答1: The changed it from change to selectionChange . <mat-select (change)="doSomething($event)"> is now <mat-select (selectionChange)="doSomething($event)"> https://material.angular.io/components/select/api 回答2: If you're using Reactive forms you can listen for changes to the select control like so.. this.form.get(

How to set environment via `ng serve` in Angular 6

白昼怎懂夜的黑 提交于 2019-11-27 10:38:12
I am trying to update my Angular 5.2 app to Angular 6. I successfully followed instructions in the Angular update guide (including the update of angular-cli to v6), and now I am trying to serve the app via ng serve --env=local But this gives me error: Unknown option: '--env' I use multiple environments ( dev/local/prod ), and this is the way it was working in Angular 5.2. How can I set the environment now in Angular 6? You need to use the new configuration option (this works for ng build and ng serve as well) ng serve --configuration=local or ng serve -c local If you look at your angular.json

How to pass multiple parameter to @Directives (@Components) in Angular with TypeScript?

强颜欢笑 提交于 2019-11-27 10:06:26
问题 Since I've created @Directive as SelectableDirective , I'm little bit confused, about how to pass more than one value to the custom directive. I have searched a lot but didn't get proper solution in Angular with Typescript . Here is what my sample code is: Parent Component as MCQComponent : import { Component, OnInit } from '@angular/core'; import { Question } from '../question/question'; import { AppService } from '../app.service/app.service'; import { SelectableDirective } from '..

How to use angular 6 Route Auth Guards for all routes Root and Child Routes?

萝らか妹 提交于 2019-11-27 10:03:14
问题 How to use angular 6 Route Auth Guards for all routes Root and Child Routes ? 回答1: 1) [ Create guard, the file name would be like auth.guard.ts ] ng generate guard auth import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { AuthService } from './auth.service'; import {Router} from '@angular/router'; @Injectable() export class AuthGuard implements CanActivate

Angular - “has no exported member 'Observable'”

£可爱£侵袭症+ 提交于 2019-11-27 09:06:59
问题 Typescript code: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; @Injectable({ providedIn: 'root' }) export class HeroService { constructor() { } getHeroes(): Observable<Hero[]> { return of(HEROES); } } error info: error TS2307: Cannot find module 'rxjs-compat/Observable'. node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find

Cross Origin Resource Sharing (CORS) in Angular or Angular 6. Problem while you make cross domain calls on localhost with different ports

送分小仙女□ 提交于 2019-11-27 06:25:57
问题 I have come across a situation where I make a call from my angular 6 application to my spring boot application. When I call an HTTP post method in angular to the application running on a different port it throws an exception. Access to XMLHttpRequest at 'http://localhost:8080/api' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. My Angular application Running on 'http:/