angular2-components

Angular2 Component: Testing form input value change

与世无争的帅哥 提交于 2019-12-03 12:32:31
I have a text input and i'm listening for the changes. mycomponent.ts ngOnInit() { this.searchInput = new Control(); this.searchInput.valueChanges .distinctUntilChanged() .subscribe(newValue => this.search(newValue)) } search(query) { // do something to search } mycomponent.html <search-box> <input type="text" [ngFormControl]="searchInput" > </search-box> Running the application everything works fine, but i want to unit-test it. So here's what i tried mycomponent.spec.ts beforeEach(done => { createComponent().then(fix => { cmpFixture = fix mockResponse() instance = cmpFixture.componentInstance

Analogue of Angular 2 Provider

我怕爱的太早我们不能终老 提交于 2019-12-02 10:51:35
问题 I have a custom component for checkbox. const CheckboxValue = new Provider( NG_VALUE_ACCESSOR, { useExisting: forwardRef(() => CheckboxComponent), multi: true }); @Component({ ... providers: [CheckboxValue] }) export class CheckboxComponent implements ControlValueAccessor { ... } As I understood in RC3 Provider was marked as deprecated. How I must rewrite my Component so that he working after next update? 回答1: It now takes an object like: const CheckboxValue = { provide: NG_VALUE_ACCESSOR,

Angular2 Table Row component on Chrome displays in single column

拈花ヽ惹草 提交于 2019-12-02 04:14:08
问题 Versions in use: Angular 2.0.1 angular-cli 1.0.0-beta.17 I have a page that is broken into 3 components. The page outline, a table which has it's own layout including rows, one of these rows contains a row component. In IE the table displays fine, in Chrome all the data from the component row appears in the first column. main.html <form> <div>Title Stuff etc.</div> <table-component [qlineModel]="QuoteLineModel"></table-component> <div>Other stuff</div> </form> table.html <table> <thead> <tr>

Angular2 Table Row component on Chrome displays in single column

青春壹個敷衍的年華 提交于 2019-12-02 00:34:32
Versions in use: Angular 2.0.1 angular-cli 1.0.0-beta.17 I have a page that is broken into 3 components. The page outline, a table which has it's own layout including rows, one of these rows contains a row component. In IE the table displays fine, in Chrome all the data from the component row appears in the first column. main.html <form> <div>Title Stuff etc.</div> <table-component [qlineModel]="QuoteLineModel"></table-component> <div>Other stuff</div> </form> table.html <table> <thead> <tr> <th>ColA</th> <th>ColB</th> <th>Option</th> </tr> </thead> <tbody> <row-component *ngFor="let qlines of

ViewChild - Not working in Angular 2 RC 1 JavaScript

浪子不回头ぞ 提交于 2019-12-01 22:47:46
问题 ViewChild is not woring in Angular 2 RC 1 JavaScript. I have used <router-outlet> . Can anyone help me to solve this issue? Thanks in advance. Following is my sample code app.AppComponent = ng.core. Component({ selector: "app", template: '<div>' + ' <router-outlet></router-outlet>' + ' <div (click)="submit()">Submit</div>' + '</div>', queries: { 'viewChild1Component': new ng.core.ViewChild(app.Child1Component) }, directives: [ng.router.ROUTER_DIRECTIVES] }) .Class({ submit: function() {

Angular2: what expressions can we interpolate in template

时间秒杀一切 提交于 2019-12-01 19:41:47
I read that we can interpolate Javascript expressions. What is the list of valid Javascript expressions that we can interpolate? So far for interpolation I have a displayed property, eg. object.property , short expressions like {{1+1}} what else Javascript expressions can we interpolate? Expressions in Angular2 are very similar to expressions in Angular in terms of the scope of what they allow. JavaScript expressions that promote side effects are prohibited including Assignment (= +=, -=) Using the new keyword Chaining expressions using a semicolon or comma Increment (++) and decrement

Generic type 'ComponentRef<C>' requires 1 type argument(s)

走远了吗. 提交于 2019-12-01 04:41:15
Unable to remove dynamic components in ionic-2. It’s saying exception while typescript compile “Generic type 'ComponentRef' requires 1 type argument(s)”. Also, the same code is working while using without using ionic2. Much appreciate your help. Thanks in Advance. class DynamicCmp { _ref: ComponentRef; _idx: number; constructor(private resolver: ComponentResolver, private location: ViewContainerRef) { } remove() { this._ref.destroy(); } add1() { this.resolver.resolveComponent(DynamicCmp).then((factory: ComponentFactory<any>) => { let ref = this.location.createComponent(factory, 0); ref

Angular 4 Component ngOnInit not called on each route request

别等时光非礼了梦想. 提交于 2019-12-01 04:06:58
I just recently started diving into Angular 4 coming from Angular 1.5. I'm working with user routes and pulling API data from a service into a user component. The component seems to stay static unlike controllers in 1.* where they were refreshed on each request. Is there anyway to have the ngOnInit function called on each new route request? My user component class: // url structure: /user/:id export class UserComponent implements OnInit { constructor(private route: ActivatedRoute) {} ngOnInit() { // doesn't log new id on route change let id = this.route.snapshot.params['id']; console.log(id);

Generic type 'ComponentRef<C>' requires 1 type argument(s)

倖福魔咒の 提交于 2019-12-01 03:17:26
问题 Unable to remove dynamic components in ionic-2. It’s saying exception while typescript compile “Generic type 'ComponentRef' requires 1 type argument(s)”. Also, the same code is working while using without using ionic2. Much appreciate your help. Thanks in Advance. class DynamicCmp { _ref: ComponentRef; _idx: number; constructor(private resolver: ComponentResolver, private location: ViewContainerRef) { } remove() { this._ref.destroy(); } add1() { this.resolver.resolveComponent(DynamicCmp).then

How to get the parent DOM element reference of an angular2 component

风流意气都作罢 提交于 2019-11-30 20:31:41
I need to access to some properties of the parent DOM element which contains the component from where i want to get the info, is there a way to do such thing? Here is how my component looks like: import { Component, Input } from "@angular/core"; import "./loadingSpinner.component.css!"; @Component({ selector: "loading-spinner", template: ` <div *ngIf="showSpinner" class="loader-directive-wrapper"> <div class="loader"></div> </div>` }) export class LoadingSpinnerComponent { @Input() public showSpinner: boolean = false; } constructor(elementRef:ElementRef) { elementRef.nativeElement