angular2-components

How to perform DOM manipulation in Angular components?

℡╲_俬逩灬. 提交于 2019-12-28 05:31:10
问题 How do we get hold of DOM elements in Angular (Version 2.x and above)? The basic functions like addClass, removeClass etc are not availble in typescript so how do we do these DOM manipulations in angular components? Please suggest if any. TIA 回答1: You can reach your DOM elements by using ViewChild decorator in this way: @Component({ .... templateUrl: 'mytemplate.html' }) export class MyComponent{ @ViewChild('selector') private someName; constructor() { //this is your dom //this.someName

Cannot Access Component Variables in Subscribe when using chrome inspector

与世无争的帅哥 提交于 2019-12-25 07:47:31
问题 Similar to this question but I already seem to have the selected answer. I have the following... import {Component, OnDestroy} from '@angular/core'; import {MdIconRegistry} from "@angular2-material/icon/icon-registry"; import {MD_ICON_DIRECTIVES} from "@angular2-material/icon/icon"; import {ShowcaseCardComponent} from "./showcase-card/showcase-card.component"; import { WheelService } from "../../wheel/wheel.service"; @Component({ selector: 'jg-showcase', template: String(require('./showcase

Angular 2 parse dynamic template as string

喜欢而已 提交于 2019-12-25 04:04:29
问题 I'm using angular 2.1 and want to dynamically import a template witch is a string from the backend. I already use ComponentFactoryResolver to load dynamically my parent container, now I need to create his content witch can look like this: <my-component> <my-nested-component> <my-nested-component> <my-component> Components are already in my applications, I just need to create them from the template string and load them into the parent. If create components from string template is not possible,

Angular2 the for attribute on a label does not link it to the input

情到浓时终转凉″ 提交于 2019-12-24 08:00:46
问题 I am working with Angular2 RC5. I have a component encapsulating a label and an input import { Component, Input} from '@angular/core'; @Component({ selector: 'my-input', template: ` <div class="mx-field" > <label [attr.for]="id"><ng-content></ng-content></label> <input type='text' id = "{{id}}" /> </div> ` }) export class InputComponent { @Input() id: string; } It is called from any template as follows <my-input id="inputcontrol">input</my-input> The problem is that when I click on the label

Angular2 access parent component's @input values

安稳与你 提交于 2019-12-23 17:33:35
问题 I'm trying to load a component dynamically using the ComponentResolver and ViewContainerRef services. The child component loads ok and the template is rendered. However i want to access the inputs from the parent ('field' and 'values') inside the child component. Any help would be much appreciated. Parent component: import {Component, Input, ViewChild, ComponentFactory, ViewContainerRef, ComponentResolver} from '@angular/core'; import {MyInputComponent} from './my-input.component'; @Component

Angular 2 - One component trigger refresh of another component on the page

时光毁灭记忆、已成空白 提交于 2019-12-23 06:59:02
问题 I have a component ComponentA that displays a list of elements . This list is inited during ngOnInit . I have another component ComponentB providing controls that might influence the list of elements shown in ComponentA. E.G. an element may be added. I need a way to trigger a reinit of ComponentA. Does someone have an idea? Details A is a HeaderBar with a menu that shows the list of "savedSearchs" @Component({ selector: 'header-bar', templateUrl: 'app/headerBar/headerBar.html' }) export class

How to create a Component with a dynamic template? (Component transclude with inline template)

社会主义新天地 提交于 2019-12-23 04:43:25
问题 I'm trying to create a component that has a dynamic template string inside of it that can access the local variables on the template. Every approach I've tried ends up with the "dynamic template string" not being $compile 'd (angular 1 terminology, please excuse me). Here is the code for the component below. Where you see the comment I would like to insert a template string that can reference item in the ngFor . @Component({ selector: 'ion-alpha-scroll', template: ` <ion-scroll [ngStyle]=

Angular 2 global component

耗尽温柔 提交于 2019-12-22 11:32:38
问题 My structure is as follows : App *component, module, template* Component 1 *component, module, template* Component 11 *component, module, template* Global Component *component, temaplte, BUT NO MODULE* My App module contains the component 1 and component 11 modules. I declared the global component in the app module, so that I can use it in all my other components. I also exported it in app module. But when I use the selector in the component 11 template, the console says not a known element .

Retain data on page reload in Angular 2

懵懂的女人 提交于 2019-12-22 09:49:09
问题 In my Angular 2 app, I pass in some data to a PageComponent from my HomeComponent which is then saved to a variable inside the PageComponent. Now when I refresh the page I need this data to be retained. Currently I am using session storage, but I was wondering if there is a better way to implement this. 回答1: Nope, There isn't a other way in this context. Once you refresh all the temporary memory is gone. As you said you are performing session-storage. You may continue with that. You may

Angular 4: Dynamic template with interpolation

余生长醉 提交于 2019-12-22 05:19:36
问题 I'm building a data table component that is being designed as very generic component. The idea is to define the table as this: <app-datatable [items]="currentPageResult"> <app-datatable-column attribute="id" header="ID"></app-datatable-column> <app-datatable-column attribute="name" header="First Name"></app-datatable-column> <app-datatable-column attribute="last_name" header="Last Name"></app-datatable-column> </app-datatable> In this way, we can specify the array into the datatable component