angular2-services

Angular2: Dependencies Between Apps created with angular-cli

独自空忆成欢 提交于 2019-12-07 02:55:28
I am using the Angular2-cli to create two applications: MyFirstApp & MySecondApp . I whish MySecondApp to import MyFirstApp so I can reuse directive/service/component. When I import MyFirstApp , I have the following compilation error: Cannot find module 'MyFirstApp' . Here's how to reproduce : $ npm -v 3.9.3 $ node -v v6.2.1 $ npm list | grep 'angular' ├── @angular/common@2.0.0-rc.1 ├── @angular/compiler@2.0.0-rc.1 ├── @angular/core@2.0.0-rc.1 ├── @angular/http@2.0.0-rc.1 ├── @angular/platform-browser@2.0.0-rc.1 ├── @angular/platform-browser-dynamic@2.0.0-rc.1 ├── @angular/router@2.0.0-rc.1 ├─

angular2 data binding between service and component properties

怎甘沉沦 提交于 2019-12-07 02:48:36
问题 I need some clarification on binding between service and component properties and data binding in angular2 assume i have a service(singleton) and a component export class Service { name = "Luke"; object = {id:1}; getName(){return this.name}; getObject(){return this.object}; } export class Component implements OnInit{ name:string; object:any; constructor(private _service:Service){} ngOnInit():any{ //Is this 2 way binding? this.name = this._service.name; this.object = this._service.object; //Is

Angular2 RxJS calling class function from map function

情到浓时终转凉″ 提交于 2019-12-07 01:21:37
问题 I'm new to Angular 2 and Observables so I apologise if my problem is trivial. Anyway I'm trying to test the Angular 2 HTTP Client using RxJS. Although I got it to work I need to add more logic to the service I'm currently working on. Basically I'd like to have a mapping function to convert the object I receive from the web service I'm connected to, to the model object I have in Angular. This is the code that works: import { Injectable } from 'angular2/core'; import { Http, Response } from

Access Parent @Component and vars from *Routed* Child Component

…衆ロ難τιáo~ 提交于 2019-12-06 19:22:54
问题 I am trying to toggle a side nav menu, located at the top of my main App template using a button in a nested child component. I can't figure out how to get to the sidenav component in the parent to tell it to sidenav.open() . I know about @Input and @Output on a child component, but as I understand it, to use this I need to have some sort of DOM tag for the child component to attach these to? Such as: <app> <sidenav-component #sidenav>...</sidenav-component> <child [someInput]="some_parent

How to fix CORS issue http request in Angular 5 [duplicate]

孤者浪人 提交于 2019-12-06 16:22:00
问题 This question already has answers here : How does Access-Control-Allow-Origin header work? (14 answers) Closed 7 months ago . I am new in Angular 5, and I want to send http request but it return CORS error in inspect element. Error XMLHttpRequest cannot load http://example.com/account/create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed

passing one component data to other component

这一生的挚爱 提交于 2019-12-06 16:17:45
I am getting response from server,I want pass this response to other component for displaying. I tried in one way but getting undefined. Tried this way how to pass one component service response to other component in angular 2 . yesterday got the results faced routing. Changed little bit created separated components. mainsearch.component.ts: export class MainsearchComponent { selected; skipCount: number = 0; errorMessage: string; searchedResults: any; searchObj: Object = { skipCount: this.skipCount }; onChange(newVlaue) { console.log(newVlaue); this.selected = newVlaue; } constructor(private

Angular - inject in other way than constructor?

徘徊边缘 提交于 2019-12-06 14:08:47
In Angular, I have a service that has few things injected through the constructor(...) . However that service is also at some place created by calling the constructor. Therefore, adding another service it depends on to the parameters would change the API. I'd like to avoid that. Is there a way to inject a service into another service without adding it to the constructor parameters? E.g. field injection? import {Inject, Injectable} from "@angular/core"; import { Http, Request, ConnectionBackend, RequestOptions, RequestOptionsArgs, Response, Headers, RequestMethod } from "@angular/http"; import

Emit and broadcast events throughout application in Angular

我的梦境 提交于 2019-12-06 13:20:55
Is there a way to emit event in angular2 that can be listened to in entire application? Like we had in AngularJS using $rootScope.broadcast and emit . Can this same thing be achieved in angular2? I read about @Output() and EventEmitter() and implemented it but it restricts only the parent to listen to the event emmitted by child. I read about BehaviorSubject being one of the ways to do this. Is that the right approach? Any other solution for this? Günter Zöchbauer In Angular2 there is no global scope. There are only components and services. With services you can define their scope by the place

Compile Angular 2 node_modules files into one file

孤街醉人 提交于 2019-12-06 10:42:26
问题 I am trying to figure out a way to compile everything I need from the angular 2 node_modules folder into one file.. It seems that there is a crazy amount of http calls when my site is loading and surely thats not optimal or the recommended process of the new and improved angular.. Im not concerned with my own typescript files as i know how to handle them but what are your approaches to concatenating the node_modules files etc ? 回答1: If you're using SystemJS 1. package.json : add these to

Angular2 http observables - how to work with undefined type

拥有回忆 提交于 2019-12-06 07:55:52
I am migrating some code from Angular1 to Angular2 and having a few issues. I can open a json response, populate a template, and access data from template ng functions but have not been able to access the data directly from the component class. From what I have read and the error messages seen Angular2 http / observable does not seem to return a pure json object, so I suspect I need to remap it, but not sure how. I believe it should also be possible to drop back to promises using onPromise but have not managed to get that working. I have spent a lot of time googling for solutions, and have