angular2-components

How to reuse a Single Component with multiple routes without creating instance of Component again

霸气de小男生 提交于 2019-12-12 06:57:20
问题 I am having two routes the first will get the list and the second get the details for each single item in a list. Initially I am displaying few values for each element in list with an action link and when the link is clicked it passes an id to method viewCoupon() and the route changes resulting in an error. How should I avoid creating an instance again and just call a different route. The code looks like below. export class CouponsComponent implements OnInit{ public couponList: Array<Coupons>

How do you sync data between two browser tabs in angular2?

試著忘記壹切 提交于 2019-12-12 04:47:33
问题 I am currently stuck in a situation where I have 3 different components and one of them is shared between the 2 two components and if I update shared component from any of the two components I want them to get updated on both of them is there a way to to do? ist-component import {Component,bind,CORE_DIRECTIVES,OnInit} from 'angular2/core'; import {MainComponent} from 'src/MainComponent'; @Component({ selector: 'my-app', directives:[MainComponent], template: `<h1>AppComponent {{onMain}}</h1>

Angular 2 reload component based on activated route

核能气质少年 提交于 2019-12-12 04:34:36
问题 I have a component which I want to re use for different router links and to reload it with server data based on the link param. From what I've seen at the moment it is suggested to have your get inside an ng zone in order to trigger the re-render of the components and its children. I am also passing the object from the http request further down to child components. This is the component onInit code: ngOnInit(): void { this.route.params.forEach((params: Params) => { let id = +params['id'];

Angular2: Pass Component Page from Service to other Component does not work

断了今生、忘了曾经 提交于 2019-12-12 03:03:36
问题 If I pass a Component Page to another via a service, that other Component fails to instantiate with "undefined [?]". How to achieve this ? (Context: so that I can centralize Component Navigation in one Service) Update This is our current workaround, ugly like most of Ionic Beta and Angular Beta if I may say so. This is our "PassThroughComponent, that gets called each time we want to navigate from component to component dynamically via the navService (we got some algorithms there calculating a

angular 2 service is not updating params

旧时模样 提交于 2019-12-11 08:07:36
问题 I have two components, one with a list of restaurants and another with the menu of the selected restaurant, to get the menu I use this service: import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http' import {Observable} from 'rxjs/Rx' import 'rxjs/add/operator/map' import { RESTAURANT_MENU } from '../../_helpers/' @Injectable() export class RestaurantsService { private menuUrl = RESTAURANT_MENU constructor(private http: Http) { } getRestaurantMenu

Calling method on Template variables giving “undefined” exception

梦想的初衷 提交于 2019-12-11 04:25:08
问题 I have one parent containing two child components. AppComponent NotificationsComponent MoveCopyComponent I want to emit values of MoveCopyComponent to NotificationComponent. Whenever I emit i get a property undefined in the NotificationComponent as shown in the screenshot <notifications #notificationsMenu role="menuitem" dropdown-item [caller]="'menu'" (acceptShareFromMenuEvent)="shareAcceptModal.PinItem($event)" (contentShareAccepted)="shareAcceptModal.hide()"> </notifications> And down

Import 3rd party javascript libraries in Angular single components

拟墨画扇 提交于 2019-12-11 02:35:46
问题 I'm currently developing an Angular4 application and I want to import some javascript libraries but just for a single component . Currently I can easily import this libraries by defining their paths inside .angular-cli.json like that: { "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/jqueryui/jquery-ui.js", "../src/assets/js/jquery/cometd/org-cometd.js", "../src/assets/js/jquery/cometd/jquery.cometd.js", ], ... } However, the mentioned scripts will be imported for

How to watch from directive on a simple variable changes inside a service?

∥☆過路亽.° 提交于 2019-12-11 01:49:45
问题 I have a simple service with data variable: import { Injectable } from '@angular/core'; @Injectable() export class MyService { private _data:number; get data(): number { return this._data; } set data(value: number) { this._data = value; } } Now from a directive I would like to catch whenever someone is doing set to my variable: this.myService.data = 12345; I was trying to do that with subscribe but missing something on syntax: this.myService.data.subscribe(res => console.log(res)); What am I

How to manipulate scss variables in Angular2 components

梦想与她 提交于 2019-12-10 17:47:18
问题 Is there a way I can change scss variables declared in Angular2 component? I want to add the theme dynamically based on user selection and hence need to modify the scss variables. I read about keeping all scss variables in a separate scss file and importing the same in other scss file. But can i import the same in my component file and modify the variables. Is this feasible? TIA Currently I am using mixin. Code goes here: // Color themes $themes: ( default: #ff0000, banana: #f1c40f, cherry:

How to hide and replace a component in Angular2

青春壹個敷衍的年華 提交于 2019-12-10 17:35:26
问题 Hello i have a parent component (A) and it has 2 child components (B and C). Parent A by default displays child component B. Now when a button is clicked that is displayed on parent A, it replaces child component B with child component C. How can i replace component B with Component C after the button is clicked in angular2? 回答1: To do that you can use the *ngIf directive or the hidden property. Note the difference: *ngIf removes and recreates the element: If the expression assigned to ngIf