angular2-services

Angular 2 Service Two-Way Data Binding

限于喜欢 提交于 2019-12-01 09:07:20
I have a salary.service and a player.component , if the salary variable gets updated in the service will the view in the player component be updated? Or is that not the case in Angular 2? When the page first loads I see the 50000 in the player.component view, so I know the two are working together. It's updating the value that's has me stumped. salary.service export class SalaryService { public salary = 50000; // starting value which gets subtracted from constructor() { } public setSalary = (value) => { this.salary = this.salary - value }; } player.component export class PlayerComponent {

how do I get angular2 dependency injection to work with value providers

微笑、不失礼 提交于 2019-12-01 08:26:42
I'm following the angular docs for Dependency Injection and tried to duplication the section on dependency injection tokens . But it's clear I still don't get it. I'm trying to use a value provider to inject an config:any into my project. At the simplest level, I just want to provide a const string // app-modules.ts const CFG_STRING = "I was declared externally and injected in ngModule" @NgModule({ imports: [ BrowserModule ], declarations: [ App ], providers: [ {provide: CFG_STRING, useValue: CFG_STRING} ], bootstrap: [ App ] }) and inject into a Component constructor // app.ts const LOCAL

how do I get angular2 dependency injection to work with value providers

十年热恋 提交于 2019-12-01 07:14:17
问题 I'm following the angular docs for Dependency Injection and tried to duplication the section on dependency injection tokens. But it's clear I still don't get it. I'm trying to use a value provider to inject an config:any into my project. At the simplest level, I just want to provide a const string // app-modules.ts const CFG_STRING = "I was declared externally and injected in ngModule" @NgModule({ imports: [ BrowserModule ], declarations: [ App ], providers: [ {provide: CFG_STRING, useValue:

How to handle multiple queryParams in Angular2

别等时光非礼了梦想. 提交于 2019-12-01 06:44:39
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'], {queryParams: {'g': myParam}}); The on the receive side, I had: this.subscription = this.route.queryParams

Angular 2 Service Two-Way Data Binding

a 夏天 提交于 2019-12-01 06:07:01
问题 I have a salary.service and a player.component , if the salary variable gets updated in the service will the view in the player component be updated? Or is that not the case in Angular 2? When the page first loads I see the 50000 in the player.component view, so I know the two are working together. It's updating the value that's has me stumped. salary.service export class SalaryService { public salary = 50000; // starting value which gets subtracted from constructor() { } public setSalary =

Angular2 Error - Is platform module (BrowserModule) included?

久未见 提交于 2019-12-01 03:34:16
问题 I'm just trying to run a simple index.html page in Angular2 , but its showing me an error in zone.js in console: Unhandled Promise rejection: No ErrorHandler. Is platform module (BrowserModule) included? ; Zone: <root> ; Task: Promise.then ; Value: Error: No ErrorHandler. Is platform module (BrowserModule) included? at eval (application_ref.ts:364) at ZoneDelegate.invoke (zone.js:391) at Object.onInvoke (ng_zone.ts:296) at ZoneDelegate.invoke (zone.js:390) at Zone.run (zone.js:141) at NgZone

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

别等时光非礼了梦想. 提交于 2019-12-01 00:19:54
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 I'm missing. Thank you. You can find all the imports in rxjs-operators.ts file and I have referenced

Reading JSON file in angular 2 application

耗尽温柔 提交于 2019-12-01 00:18:35
I have a file data.json which I want to import in my angular 2 application. I am getting file with HTML input tag. <input type="file" (change)="onImport($event)"/> in my typescript file I want to read this data.json file and store the content of file in JSON array. I have searched but couldn't find any way to read file or any library which could help me with this. Use FileReader from the File API and JSON.parse() method like: onImport(event) { var file = event.srcElement.files[0]; if (file) { var reader = new FileReader(); reader.readAsText(file, "UTF-8"); reader.onload = function (evt) {

create an angular 2 service in es5

爱⌒轻易说出口 提交于 2019-12-01 00:00:25
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 into my component it throws the error no provider for class0 (class10 -> class0) i can't seem to

Importing AWS SDK in Angular 2 Application

半腔热情 提交于 2019-11-30 20:28:36
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 type of import, I don't get a transpiler error until I attempt to access a library within the AWS object,