angular2-services

Angular 2 - Including a provider in a service

半城伤御伤魂 提交于 2019-12-02 08:11:35
I have a service loaded into a component as a provider. This service may return data using Http or it may not, the component should not care. However, it seems that the component itself must include HTTP_PROVIDERS if the loaded service uses Http. This breaks separation of concerns. What am I misunderstanding? This breaks separation of concerns. What am I misunderstanding? In order to support instantiating multiple instances of a service (i.e., so all services don't have to be singletons), an Angular app needs a way to specify multiple injectors (not just one). These injectors need to be

ViewChild - Not working in Angular 2 RC 1 JavaScript

浪子不回头ぞ 提交于 2019-12-01 22:47:46
问题 ViewChild is not woring in Angular 2 RC 1 JavaScript. I have used <router-outlet> . Can anyone help me to solve this issue? Thanks in advance. Following is my sample code app.AppComponent = ng.core. Component({ selector: "app", template: '<div>' + ' <router-outlet></router-outlet>' + ' <div (click)="submit()">Submit</div>' + '</div>', queries: { 'viewChild1Component': new ng.core.ViewChild(app.Child1Component) }, directives: [ng.router.ROUTER_DIRECTIVES] }) .Class({ submit: function() {

Angular 2 when passing id in url it's showing ?complntId=TS0000031

ε祈祈猫儿з 提交于 2019-12-01 22:27:25
问题 have a scenario,if user enters one number and submit it should navigate to that id and display the details. when i navigate url,it's showing something like this complaintstatus/TS0000031?complntId=TS0000031 Detail view code: export class ComplaintDetailComponent implements OnInit { id:number; private sub:any; complntId : any; constructor(private ComponentService:ComplaintService,private route:ActivatedRoute){ } ngOnInit() { this.sub= this.route.params.subscribe((params:Params)=>{ this

Angular 2 when passing id in url it's showing ?complntId=TS0000031

不想你离开。 提交于 2019-12-01 21:41:41
have a scenario,if user enters one number and submit it should navigate to that id and display the details. when i navigate url,it's showing something like this complaintstatus/TS0000031?complntId=TS0000031 Detail view code: export class ComplaintDetailComponent implements OnInit { id:number; private sub:any; complntId : any; constructor(private ComponentService:ComplaintService,private route:ActivatedRoute){ } ngOnInit() { this.sub= this.route.params.subscribe((params:Params)=>{ this.ComponentService.getCompliants(params['complntId']) }); console.log(this.sub); } user enters id code : export

Iterate through an array of objects Angular 2

ⅰ亾dé卋堺 提交于 2019-12-01 18:49:45
I have an array of objects received in service file from a json file. When I subscribe it in the component and try to iterate through it, I am getting the following error: EXCEPTION: Error in app/dashboard/features/fleet/fleetControlPanel/fleetControlPanelTemplate.html:38:14BrowserDomAdapter.logError @ browser_adapter.ts:78BrowserDomAdapter.logGroup @ browser_adapter.ts:89ExceptionHandler.call @ exception_handler.ts:53(anonymous function) @ application_ref.ts:304schedulerFn @ async.ts:131SafeSubscriber.__tryOrUnsub @ Subscriber.ts:240SafeSubscriber.next @ Subscriber.ts:192Subscriber._next @

How can a mock a http observable in Angular2 for when no api is written

杀马特。学长 韩版系。学妹 提交于 2019-12-01 16:17:15
I'm new to both Angular2 and Rxjs and I am a little confused about a particular case. I have a simple service: import { Injectable } from '@angular/core'; import { Observable, Subject } from 'rxjs/Rx'; import { Http, Response } from '@angular/http'; export interface Article { id: number; title: string; content: string; author: string; } @Injectable() export class ArticleService { private _articles$: Subject<Article[]>; private baseUrl: string; private dataStore: { articles: Article[] }; constructor(private http: Http) { this.baseUrl = 'http://localhost:3000' this.dataStore = { articles: [] };

Get angular 2 service inside a custom class instantiated by me

拟墨画扇 提交于 2019-12-01 14:55:17
Im building an angular 2 app, and i need a way to get a reference to a service/class that is injected/instantiated by angular framework. I have a generic class...lets call it Custom class, that i use throughout the site. This class, however is instantiated by me, not angular 2. Now, i need to use some of the services instantiated by angular 2 inside that class. i.e // this is not angular component/service export default class Custom { constructor(properties) { } doSomething() { // UserService is a service that is injected into other componetns constructors, but this class is not a component. /

How can a mock a http observable in Angular2 for when no api is written

喜你入骨 提交于 2019-12-01 14:29:09
问题 I'm new to both Angular2 and Rxjs and I am a little confused about a particular case. I have a simple service: import { Injectable } from '@angular/core'; import { Observable, Subject } from 'rxjs/Rx'; import { Http, Response } from '@angular/http'; export interface Article { id: number; title: string; content: string; author: string; } @Injectable() export class ArticleService { private _articles$: Subject<Article[]>; private baseUrl: string; private dataStore: { articles: Article[] };

Expressjs to upload an image using multer saves an image in a weird format

僤鯓⒐⒋嵵緔 提交于 2019-12-01 13:44:41
I am trying to build an API which will take in image so used multer for that purpose, I am getting a success for uploading an image but it saves in some weird format not the actual format I tried to save. I ll post the related code here. in app.js const multer = require('multer'); app.use(function(req, res, next) { //allow cross origin requests res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS, DELETE, GET"); res.header("Access-Control-Allow-Origin", "http://localhost:3001"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res

Get angular 2 service inside a custom class instantiated by me

爱⌒轻易说出口 提交于 2019-12-01 12:14:49
问题 Im building an angular 2 app, and i need a way to get a reference to a service/class that is injected/instantiated by angular framework. I have a generic class...lets call it Custom class, that i use throughout the site. This class, however is instantiated by me, not angular 2. Now, i need to use some of the services instantiated by angular 2 inside that class. i.e // this is not angular component/service export default class Custom { constructor(properties) { } doSomething() { // UserService