angular2-services

Promise and subscribe

北慕城南 提交于 2019-11-30 20:06:53
I have an Angular2 (ionic2) application. I have a function that request cities but I get an error that Property subscribe does not exists on this.cityService.getAllCities() . cityPage.ts has a function like this: getCities(){ this.cityService.getAllCities() .subscribe(cityData => { this.cityList = cityData; }, err => console.log(err), () => console.log('Complete!') ); } my cityService.getAllCities() function looks like this: getAllCities(){ return new Promise (resolve => { this.storage.ready().then(() => { this.storage.get('authData').then(authData => { let hdr = new Headers({'Content-Type':

Angular 2: Property 'toPromise' does not exist on type 'Observable<Response>'

老子叫甜甜 提交于 2019-11-30 19:06:45
问题 I'm developing Angular 2 project and following Http Client Guide for implementing HTTP request But receiving following error when using RsJx module. Property 'toPromise' does not exist on type 'Observable' I have done the following but error still persist: Added import 'rxjs/add/operator/toPromise' ; to service module Checked the version of RxJs library for any dependency. imported all modules from RxJs library You can find my source code here on Github. Please guide what should I do and what

Angular 2 - Implementation of shared services

喜你入骨 提交于 2019-11-30 18:58:10
问题 I'm trying to implement a solution I found right here in Stack Overflow, but facing difficulty. I've a service and a component and something is not correct on the implementation. The error: TypeError: Cannot read property 'next' of undefined What could be wrong or missing ? Is there something more missing ? Also on my terminal window, I got this error, but it's not reflect on my browser console: error TS1005: '=>' expected. import {Injectable} from 'angular2/core'; import {Observable} from

create an angular 2 service in es5

China☆狼群 提交于 2019-11-30 18:06:23
问题 Im trying to create a custom service in angular 2 but i can't seem to find any documentation on angular 2 services in es5 (which is what im writing my code in) i've tried using this (function(app){ app.database=ng.core.Injectable().Class({ constructor:[function(){ this.value="hello world"; }], get:function(){return this.value}, }); ng.core.Injector.resolveAndCreate([app.database]); ng.core.provide(app.database,{useClass:app.database}); })(window.app||(window.app={})); however when i inject it

Importing AWS SDK in Angular 2 Application

不羁岁月 提交于 2019-11-30 17:01:40
问题 I am attempting to use the AWS SDK in my Angular 2 application and am getting quite stuck. Here are the steps I have taken: Installed the aws sdk into my Angular 2 application using npm install aws-sdk Installed the types using npm install --save-dev @types/node Attempted to include the AWS modules several different ways in my Angular 2 service: declare var AWS: any; , import AWS = require('aws-sdk'); , and finally import * as AWS from 'aws-sdk'; . when I attempt to use the first and third

Static Methods and Angular 2 Services in JavaScript ES6

我的未来我决定 提交于 2019-11-30 12:48:01
问题 While coding an app with Angular 2 and multiple calculation services I faced the following questions: When do I use static in a Angular service provided on application level? Is that nonsense? How does a static method reflect on performance? Lets say a couple hundret objects call at the same time the same static method. Is this method instantiated more than once? This is a snap of the class, that provides me multiple calculation methods and is instantiated on application level: @Injectable()

Bind a service property to a component property with proper change tracking

旧街凉风 提交于 2019-11-30 11:16:13
Consider the utterly simple Angular 2 service: import { Injectable } from '@angular/core'; import {Category} from "../models/Category.model"; @Injectable() export class CategoryService { activeCategory: Category|{} = {}; constructor() {}; } And then the component using this service: import { Component, OnInit } from '@angular/core'; import {CategoryService} from "../shared/services/category.service"; import {Category} from "../shared/models/Category.model"; @Component({ selector: 'my-selector', template: ` {{categoryService.activeCategory.Name}}<br/> {{category.Name}}<br/> `, }) export class

What is multi provider in angular2

被刻印的时光 ゝ 提交于 2019-11-30 11:10:43
I understand that provider is for getting service from another class but what is multi-provider and token thing? And also when we do multi=true ? provide(NG_VALIDATORS, { useExisting: class), multi: true }) multi: true means that one provider token provides an array of elements. For example all directives for router support routerLink , router-outlet are provided by ROUTER_DIRECTIVES . If a new provider is registered with the token ROUTER_DIRECTIVES , then it overrides the previously registered directives. If multi: true (on the first registered and the new provider) is set, the new directives

Angular2: Convert XML to JSON

♀尐吖头ヾ 提交于 2019-11-30 09:16:49
I wanted to convert the XML I received from Web API response to JSON in Angular 2. The application is developed in Nativescript. Not able to find a solution for this. I found an amazing package to make this very simple. xml2js For me on I am doing it in an angular 2 application but on the node side. npm install xml2js --save It is literally as simple as passing the xml like this, var parseString = require('xml2js').parseString; var xml = "<root>Hello xml2js!</root>" parseString(xml, function (err, result) { console.dir(result); }); In my app I had an xml file and used it like this, var fs =

RxJs subscribers, passing null values?

荒凉一梦 提交于 2019-11-30 09:02:46
I've spent the day diving into RxJS with Angular2, as the practice of modeling user interfaces as streams is new to me. I'm experimenting with a user service that provides a stream of User objects. The first User object will be provided when the user is authenticated. Additional User Objects may be provided when the User is updated, e.g. they update their profile. If the user is not logged when the application loads, or they logout, then null is emitted. As such, an observer implementation in a component would look like this: export class AppComponent { private user: User; private