angular2-services

JSON response is in array but still throws an error “NgFor only supports binding to Iterables such as Arrays”

荒凉一梦 提交于 2020-01-24 14:26:07
问题 TypeScript File export class CompanyComponent { apiService : APIService; data : any; private companyUrl = 'http://localhost:4000/api/company/'; constructor(apiService : APIService) { this.apiService = apiService; this.getCompanies(this.companyUrl); } getCompanies(url: any){ this.data = this.apiService.GET(url).map((response :Response)=> response.json()).subscribe((response)=>{ this.data = response; console.log(this.data); }) } Response array [ {"_id":"58f61a132d44240d085ca2fa","comapny_name":

How to inject service to class and then extend component with it?

为君一笑 提交于 2020-01-24 12:26:48
问题 I have class Layer : import {AfterViewInit, ViewChild} from 'angular2/core'; export class Layer implements AfterViewInit { @ViewChild('element') element; public canvas: HTMLCanvasElement = null; public context: CanvasRenderingContext2D = null; ngAfterViewInit() { this.canvas = this.element.nativeElement; this.context = this.canvas.getContext('2d'); } } which I will be extending with my component Lines : import {Component} from 'angular2/core'; import {Layer} from './layer'; import {Game} from

How to inject service to class and then extend component with it?

我怕爱的太早我们不能终老 提交于 2020-01-24 12:24:33
问题 I have class Layer : import {AfterViewInit, ViewChild} from 'angular2/core'; export class Layer implements AfterViewInit { @ViewChild('element') element; public canvas: HTMLCanvasElement = null; public context: CanvasRenderingContext2D = null; ngAfterViewInit() { this.canvas = this.element.nativeElement; this.context = this.canvas.getContext('2d'); } } which I will be extending with my component Lines : import {Component} from 'angular2/core'; import {Layer} from './layer'; import {Game} from

Upload a JSON Object (User information) and Multiple Image with single request. Angular + Spring Boot

守給你的承諾、 提交于 2020-01-23 17:09:13
问题 Spring Rest Controller @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<PersonDTO> createPerson(@RequestParam("user") User personDTO, @RequestParam("file") MultipartFile[] file){ return new ResponseEntity<>(null, responseHeaders, HttpStatus.OK); } Angular Service createPerson(personClass : User, files : File[]): Observable<HttpEvent<{}>>{ let formdata: FormData = new FormData(); //Get Cities var obj = JSON.parse(JSON.stringify(personClass.city)); var myObj =

EventEmitter in angular services, good or bad?

浪子不回头ぞ 提交于 2020-01-16 18:09:28
问题 I was using EventEmitter and @Output in Angular services, today one of the coleagues mentioned it's not a good practice. I found this post mentioning it's a bad practice and it seems mostly is personal opinion, and this answer is mentioning it's OK to use it. I couldn't find any official document about it, so if somebody knows an official answer for it please post. Official doc about EventEmittter 回答1: I was using EventEmitter and @Output in Angular services, today one of the coleagues

canActivate doesn't respond upon subscription change Angular 2 Router AngularFire2

半城伤御伤魂 提交于 2020-01-15 03:44:26
问题 I'm using AngularFire2. This is how I approached my AuthGuard service: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { this.af.auth.subscribe((auth) => { if(auth == null) { this.router.navigate(['/login']); this.allowed = false; } else { this.allowed = true; } }) return this.allowed; } The above code works, except when I visit a guarded page directly (i enter URL in browser), it doesn't load the respective component after the subscription resolves to true. In

Loading JSON Without an HTTP Request

放肆的年华 提交于 2020-01-14 14:54:06
问题 I am working on a project using Angular 4, NPM, Node.js, and the Angular CLI. I have a rather unusual need to load JSON into an Angular service (using an @Injectable ) without an HTTP request, i.e. it will always be loaded locally as part of the package, and not retrieved from a server. Everything I've found so far indicates that you either have to modify the project's typings.d.ts file or use an HTTP request to retrieve it from the /assets folder or similar, neither of which is an option for

Watch for changes in Angular 2 services function

巧了我就是萌 提交于 2020-01-13 10:48:05
问题 I have a service named HomeService and in that service I am setting and getting some data which is working fine. Here is the code for my service. import { Injectable } from '@angular/core'; @Injectable() export class HomeService { name:string; constructor() { } setParams(val) { this.name = val; } getParams() { return this.name; } } I am setting params in a component A and getting it in component B . What I want is to keep watching the getParams() for changing in the second component. I am

Angular 2 Service… Pointless?

戏子无情 提交于 2020-01-13 05:49:29
问题 I have been using angular 2 for about 2 weeks now and I love it with the exception of one thing... Services. Despite using them, to conform to society, I don't understand the point and I hope some one can explain the reasoning. Services don't do anything besides load data. Not to mention 9/10 what ever component I inject it into has to have similar functions to handle the data returned and make it usable. Another big problem I have with them is the overhead. Lets say (Following the heroes

How to handle multiple queryParams in Angular2

◇◆丶佛笑我妖孽 提交于 2020-01-11 06:13:10
问题 I'm trying to implement a filtering mechanism in a new Angular2 app, that would allow me to filter a list of entries in an array. The entries may have around 20 properties that could be filtered on. I have so far created a list of filters in one component and then a list component that is routed to, as a child. I then planned to pass the filters as queryParams through the router. Starting with just one filter this was fine: On the send side I had: this.router.navigate(['/findlist'],