angular2-services

Web workers in Angular 2 Dart

喜欢而已 提交于 2019-11-30 07:43:29
I'm experimenting with angular 2 for a large project that would benefit from handing off tasks to web workers. I've found examples of ng2 web workers for JavaScript and TypeScript but struggling to convert these into dart equivalent. Has anyone done this? Or know how to do this? Below is my current main.dart bootstrap file, the AppComponent should have access to the UI, and the CustomerService work in a worker. import 'package:angular2/platform/browser.dart'; import 'package:angular2/web_worker/ui.dart'; import 'package:ngMegatron/app_component.dart'; import 'package:ngMegatron/services

Angular2: which is the best way to make multiple sync calls with Observables?

筅森魡賤 提交于 2019-11-30 07:29:11
I'm studying the Observables in Angular2/4, before I've used the Promises for my services call. I'm wondering what is the best way to make multiple sync calls. Let me explain with an example: my app component have a getUserInfo() method that need to make 3 calls to 3 different services that depends on each other. getUserId():Number // return the logged in user userId from the session getUserPermissions(userId):Array<String> // return a list of permission from the userId getUserInfo(userId):String // return some additional info for the user Now let suppose that I have an User object as the

property 'forkJoin' does not exist on type 'typeof observable' - angular2

被刻印的时光 ゝ 提交于 2019-11-30 07:03:59
问题 I was looking to experiment with a forkJoin mainly using the accepted answer here: Angular2 Observable.forkJoin of observable variables - ReferenceError: Observable is not defined I'm getting the above error message as forkJoin isn't available. Anyone know why? 回答1: Angular 6 changes this up a bit. forkJoin has been converted to a regular function so, instead of: import {Observable} from 'rxjs/Observable'; ... return Observable.forkJoin( this.http.get('someurl'), this.http.get('someotherurl')

Angular2 Lazy Loading Service being Instantiated Twice

蹲街弑〆低调 提交于 2019-11-30 02:44:27
问题 I just switched my application over to be lazy-loaded today. I have a SharedModule that exports a bunch of services. In my AppModule , I import SharedModule because AppComponent needs access to a few of the shared services. In another module FinalReturnModule , I import SharedModule . In one of my services, I put a console.log('hi') in the constructor. When the app first loads, I get hi to the console. Whenever I navigate to a page within the FinalReturnModule I get hi again. Obviously, since

Angular 2 animate *ngFor list item one after other using new Animation support in RC 5

我是研究僧i 提交于 2019-11-29 22:24:45
I have a component that fetches list of items from server and then display that list using *ngFor in template. I want the list to be displayed with some animation, but one after other. I mean each list item should animate in after other. I am trying something like this: import { Component, Input, trigger, state, animate, transition, style } from '@angular/core'; @Component({ selector: 'list-item', template: ` <li @flyInOut="'in'">{{item}}</li>`, animations: [ trigger('flyInOut', [ state('in', style({ transform: 'translateX(0)' })), transition('void => *', [ style({ transform: 'translateX(-100%

How can I detect service variable change when updated from another component?

一世执手 提交于 2019-11-29 21:02:49
I'm trying to get the updated value from a service variable ( isSidebarVisible ) which is keeps on updated by another component ( header ) with a click event ( toggleSidebar ). sidebar.service.ts import { Injectable } from '@angular/core'; import { Subject } from 'rxjs/Subject'; @Injectable() export class SidebarService { isSidebarVisible: boolean; sidebarVisibilityChange: Subject<boolean> = new Subject<boolean>(); constructor() { this.isSidebarVisible = false; } toggleSidebarVisibilty() { this.isSidebarVisible = !this.isSidebarVisible this.sidebarVisibilityChange.next(this.isSidebarVisible);

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

自闭症网瘾萝莉.ら 提交于 2019-11-29 17:19:38
问题 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

What is multi provider in angular2

余生颓废 提交于 2019-11-29 16:09:21
问题 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 }) 回答1: 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

Angular2: Convert XML to JSON

泄露秘密 提交于 2019-11-29 14:10:48
问题 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. 回答1: 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,

Why am I getting a error loading rxjs-extensions in Angular 2?

六眼飞鱼酱① 提交于 2019-11-29 14:03:25
I have been following the tour of heroes tutorial on the angular2 website step by step but I have come across a little snag when I got to the http section of the tutorial. Why do I keep getting these errors in the console? "GET http://localhost:3000/app/rxjs-extensions.js 404 (Not Found)" AND "Error: Error: XHR error (404 Not Found) loading http://localhost:3000/app/rxjs-extensions.js (…)" This is my systemjs.config.js : (function(global) { // map tells the System loader where to look for things var map = { 'app': 'app', // 'dist', '@angular': 'node_modules/@angular', 'angular2-in-memory-web