angular2-directives

Implementing autocomplete

半城伤御伤魂 提交于 2019-12-03 01:50:35
问题 I am having trouble finding a good autocomplete component for Angular2. Just anything that I can pass a list of key-label objects to and have a nice autocomplete on an input field. Kendo does not support Angular 2 yet and that it what we mostly use internally. It doesn't appear that Angular Material supports Angular 2 yet either. Can anyone please point me in the right direction or let me know what they are using? This is what I built so far. It's pretty bad and I'd like to find something

Detect Click outside element in angular 4 using directives

那年仲夏 提交于 2019-12-03 00:09:24
I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4. [plunkr] https://plnkr.co/edit/aKcZVQ?p=info When I try using the same code in angular-4 I get the following errors: 1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> @Component({ templateUrl: "", directives: [ClickOutside] }) 2. Type 'Subscription' is not assignable to type 'Observable<MouseEvent>'. in the directive inside ngOnInit() and ngOnDestroy() ngOnInit() { this.globalClick =

How to put a component inside another component in Angular2?

我的梦境 提交于 2019-12-02 23:26:25
I'm new at Angular and I'm still trying to understand it. I've followed the course on the Microsoft Virtual Academy and it was great, but I found a little discrepancy between what they said and how my code behave! Specifically, I've tried to "put a component inside another component" like this: @Component({ selector: 'parent', directives: [ChildComponent], template: ` <h1>Parent Component</h1> <child></child> ` }) export class ParentComponent{} @Component({ selector: 'child', template: ` <h4>Child Component</h4> ` }) export class ChildComponent{} This is the same example that they make on the

Angular 2 Focus on first invalid input after Click/Event

不羁的心 提交于 2019-12-02 22:34:58
I have an odd requirement and was hoping for some help. I need to focus on the first found invalid input of a form after clicking a button (not submit). The form is rather large, and so the screen needs to scroll to the first invalid input. This AngularJS answer would be what I would need, but didn't know if a directive like this would be the way to go in Angular 2: Set focus on first invalid input in AngularJs form What would be the Angular 2 way to do this? Thanks for all the help! This works for me. Not the most elegant solution, but given the constraints in Angular we are all experiencing

Angular 2+ - Set ngModel to null when ngIf causes hide

大兔子大兔子 提交于 2019-12-02 20:32:07
问题 I have an issue similar to Reset ngModel values on ngIf in angular2 I would like to set any ngModel values to null whenever a parent *ngIf causes that element to be hidden. I wouldn't be asking this if my situation was simple. If that were the case, then I'd just reset on the change of the *ngIf value, but since my form has multiple levels of *ngIf nesting and multiple *ngIfs can cause some elements to show/hide, I'd like to use some sort of directive to accomplish the resetting. I'd rather

Angular 2 make @Input on directive required

跟風遠走 提交于 2019-12-02 17:28:17
In Angular 1 we could make a directive attribute required. How do we do that in Angular 2 with @Input? The docs don't mention it. Eg. Component({ selector: 'my-dir', template: '<div></div>' }) export class MyComponent { @Input() a:number; // Make this a required attribute. Throw an exception if it doesnt exist @Input() b:number; constructor(){ } } Günter Zöchbauer Check in ngOnInit() (inputs aren't yet set when the constructor is executed) whether the attribute has a value. Component({ selector: 'my-dir', template: '<div></div>' }) export class MyComponent implements OnInit, OnChanges { @Input

TypeError: Cannot read property 'createComponent' of undefined

£可爱£侵袭症+ 提交于 2019-12-02 16:26:49
问题 I am trying to load a component dynamically from a parent component. While loading the child component I need to pass some input parameter as well. But I am getting the following error in the browser console. Error: Uncaught (in promise): TypeError: Cannot read property 'createComponent' of undefined at resolvePromise (zone.js:538) at zone.js:574 at ZoneDelegate.invokeTask (zone.js:356) at Object.onInvokeTask (lib/@angular/core/bundles/core.umd.js:9091) at ZoneDelegate.invokeTask (zone.js:355

Implementing autocomplete

依然范特西╮ 提交于 2019-12-02 14:02:59
I am having trouble finding a good autocomplete component for Angular2. Just anything that I can pass a list of key-label objects to and have a nice autocomplete on an input field. Kendo does not support Angular 2 yet and that it what we mostly use internally. It doesn't appear that Angular Material supports Angular 2 yet either. Can anyone please point me in the right direction or let me know what they are using? This is what I built so far. It's pretty bad and I'd like to find something that looks nice. import {Component, EventEmitter, Input, Output} from 'angular2/core'; import {Control}

TypeError: Cannot read property 'createComponent' of undefined

倾然丶 夕夏残阳落幕 提交于 2019-12-02 11:07:41
I am trying to load a component dynamically from a parent component. While loading the child component I need to pass some input parameter as well. But I am getting the following error in the browser console. Error: Uncaught (in promise): TypeError: Cannot read property 'createComponent' of undefined at resolvePromise (zone.js:538) at zone.js:574 at ZoneDelegate.invokeTask (zone.js:356) at Object.onInvokeTask (lib/@angular/core/bundles/core.umd.js:9091) at ZoneDelegate.invokeTask (zone.js:355) at Zone.runTask (zone.js:256) at drainMicroTaskQueue (zone.js:474) at XMLHttpRequest.ZoneTask.invoke

Angular 2+ - Set ngModel to null when ngIf causes hide

好久不见. 提交于 2019-12-02 07:57:30
I have an issue similar to Reset ngModel values on ngIf in angular2 I would like to set any ngModel values to null whenever a parent *ngIf causes that element to be hidden. I wouldn't be asking this if my situation was simple. If that were the case, then I'd just reset on the change of the *ngIf value, but since my form has multiple levels of *ngIf nesting and multiple *ngIfs can cause some elements to show/hide, I'd like to use some sort of directive to accomplish the resetting. I'd rather not have to convert all my simple input elements to components to take advantage of the OnDestroy event,