Questions tagged [angular2-directives]

Use for questions about Angular 2+ directives

1806 questions
11
votes
2 answers

Add a component dynamically to a child element using a directive

Trying to place a component dynamically to a child element, using a directive. The component (as template): @Component({ selector: 'ps-tooltip', template: `
11
votes
1 answer

Angular 2: focusing input causes 'expression has changed after it was changed' error

In my Angular 2 application, I want to have a list of inputs. Pressing Enter inside one of them would add a new input and immediately focus on it. This is a question that has already been asked on this site and Eric Martinez provided a neat answer…
kamilk
  • 3,829
  • 1
  • 27
  • 40
11
votes
4 answers

Can the ViewChildren Decorator in Angular2 work with Interfaces?

The way I understand Angular 2, the ViewChildren decorator allows a Component to get a Query for other Components or Directives. I can get this to work in Typescript when I know the specific Type of the Component, but I would like to be able to get…
brianv
  • 143
  • 1
  • 7
11
votes
3 answers

How to dynamically bind the value of a checkbox Angular 2

Hi all: I have a component. The component view has a table:

Recipients List


Bob Zhang
  • 841
  • 3
  • 10
  • 17
10
votes
6 answers

Can't bind to 'placeholder' since it isn't a known property of 'ng-multiselect-dropdown'

I want to implement autocomplete feature , so an identical option i found was using multi-select drop-down. So i used this module - https://www.npmjs.com/package/ng-multiselect-dropdown But after ditto implementing, i get these errors - Error…
Techdive
  • 997
  • 3
  • 24
  • 49
10
votes
3 answers

How to restrict Special character in material input

I have a material input control, i have restrict the special character while user enter, but when type some words in any editor and copy and paste the words with special character, which is not working. I have write the directive for that to prevent…
10
votes
2 answers

Limit directive to specific host (component) in Angular

Is is possible to limit which component can have custom directive? For example: @Directive({ selector: '[myHighlight]', host: "my-component" //!!!!!!!!! }) export class HighlightDirective { constructor(el: ElementRef) { //el is…
Makla
  • 9,899
  • 16
  • 72
  • 142
10
votes
2 answers

@Viewchild is not working inside Directive, but working in Component

I am just playing around with @ViewChild/@ContentChild, and I was surprised to see that the @ViewChild is not working inside directive and is working fine for component.But in Directive its not working. I tried with AfterViewInit hook, so life cycle…
10
votes
1 answer

Angular2: Is one time binding for *ngIf available?

I am creating a DOM structure and only want to add some parts in some visual components at first time and do not want them to be refreshed again and again which is the way *ngIf would work. This is to avoid bindings to execute again and again for…
Abhi
  • 1,624
  • 2
  • 16
  • 29
10
votes
1 answer

Angular2 - Directive not working when not declared in the same module

I have a directive and I want to use it in multiple modules. Declaring it on each modules produces an error. Thus, I tried to declare it in a shared module and import this shared module to other modules. However, it didn't work. It only works when…
10
votes
1 answer
Id Name Inside the directive, I have HostBindings for adding classes based on the event and HostListeners for listening for mouseenter and mouseleave events. For example:…
Lee
  • 601
  • 9
  • 21
10
votes
4 answers

How to add some html elements using Angular2's attribute directive

If a certain attribute directive is present on an HMTL element, I would like to show some additional html content. I have searched but can't find what am looking for. For example if P tag has a directive called can-delete, then I would like delete…
user1275105
  • 2,643
  • 5
  • 31
  • 45
10
votes
3 answers

Change an input's ngModel value using a directive Angular 2

I'm stuck on how to access and change an inputs ngModel value using a directive. The outcome of the issue is that the model's address value doesn't update when I select the desired address...it's just set to what I actually typed into the input,…
sharpmachine
  • 3,783
  • 6
  • 19
  • 24
10
votes
3 answers

How to send a value from one component to another?

I make a componenet in which I have one input field and button.On click of button I am diplaying the second component.I want to send data from one component to another component ? how I will send data from one component to another ..I need to send…
user944513
  • 12,247
  • 49
  • 168
  • 318
9
votes
1 answer

Selector in Directives

The following directive should hide an element. import {Directive, ElementRef, Input, Renderer2} from '@angular/core'; import {el} from "@angular/platform-browser/testing/src/browser_util"; // Directive decorator @Directive({ selector: '[hide-me]'…
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184