Use for questions about Angular 2+ directives
Questions tagged [angular2-directives]
1806 questions
15
votes
1 answer
Disable ngbDatepicker input
Im using ngbDatepicker and ng2-datepicker-jalali. I use ngbDatepicker directive like below:

Hadi Rasouli
- 1,871
- 3
- 27
- 43
15
votes
2 answers
Are impure pipes in Angular 2 (pure = false) bad for my performance?
I have a translate pipe, which accepts a string as key, and returns the translated string from a dictionary. The pipe looks like this:
import {Pipe, PipeTransform} from 'angular2/core';
import {TranslateService} from './translate.service';
@Pipe({
…

Jeroen1984
- 1,616
- 1
- 19
- 32
14
votes
1 answer
Angular structural directive: wrap the host element with some another component
I have simplest Angular structural directive:
import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';
@Directive({ selector: '[hello]' })
export class HelloDirective {
constructor(
private templateRef: TemplateRef,…

dhilt
- 18,707
- 8
- 70
- 85
14
votes
1 answer
Anchor Jumping across the section within page
I am trying to implement "Anchor Jumping" functionality using JavaScript and Angular 2 in my application, Means user can jump across the section within a page.
As per the client requirement, User can jump(Navigate) the section using of pressing…

Dipak Delvadiya
- 2,112
- 2
- 19
- 33
14
votes
3 answers
Angular2 forEach cant read property
How can I call this.firms within a data forEach()?
I know how to do this in Angular1, but not with my current project in Angular 2.
Currently it works fine outside of the forEach, but not within.
console.log(this.firms[0].name); // works
var a…

maria
- 207
- 5
- 22
- 56
14
votes
3 answers
How to listen to children elements events in a directive?
Since there is no template, what's the best way to listen to child elements event in a directive? Is it possible with HostListener? If not, is there any other way?
There's also this similar question: How to listen for child event from parent…

Maxime Dupré
- 5,319
- 7
- 38
- 72
14
votes
2 answers
Detect change in a variable?
Is it possible to detect change in a variable?
I have the following:
@Input('name') name: string;
I would like to call a function whenever change is happened in this variable 'name'.
Is it possible?

Renato Souza de Oliveira
- 4,236
- 4
- 20
- 31
14
votes
3 answers
How to display error message based on custom validation rules in Angular 2?
I am using a template-driven approach to building forms in Angular 2 and I have successfully created custom validators that I can use in the template.
However, I can't find a way to display specific error message bound to specific errors. I want to…

eloquent_poltergeist
- 195
- 1
- 1
- 7
14
votes
3 answers
Angular2 Directive to modify click handling
I am trying to write a Angular2 attribute directive to modify the behaviour of certain elements. More specifically I want to apply an attribute to certain elements that have click handlers and prevent the bound function to be executed under certain…

masimplo
- 3,674
- 2
- 30
- 47
14
votes
4 answers
How to load image with spinner in angular2
my app got many images with descriptions. When user navigates these text is coming first and image is loading with some delay. I would like to add a spinner here. A directive which shows spinner while loading the image and shows image like

Mujibur Rahman
- 313
- 1
- 5
- 17
14
votes
5 answers
Angular Directive
has anyone created any sample Angular Directive using @Directive decorator? I searched a lot on however all developers so far created component directives. Even Angular API Review doesn't speak more on this.

Avi Kenjale
- 2,414
- 6
- 29
- 46
13
votes
2 answers
Adding a Component to a TemplateRef using a structural Directive
We are building an angular 4 component library and one of the components is a Busy component. The purpose of the component is to allow a developer to create an overlay on any given HTML element which contains a spinner graphic.

Rob
- 131
- 1
- 1
- 4
13
votes
3 answers
Dynamic ngTemplateOutlet value
Is there a way to dynamically set the value of the *ngTemplateOutlet directive?
Something along those lines:
…

atcastroviejo
- 253
- 1
- 3
- 10
13
votes
1 answer
Angular 2 Directive implementing ControlValueAccessor doesn't update 'touched' property on change
I'm trying to create my own Angular 2 Directive for Jquery UI Datepicker. I've seen some different approaches on the internet and in SO as well, but no one achieves the goal that I want to. So this is the code that I have so far:
import {Directive,…

Pasp Ruby
- 957
- 1
- 9
- 22
13
votes
2 answers
How to check if Change Detection was triggered on a component
In my app I want to set manual change detection. For this I set the ChangeDetectionStrategry to OnPush and whenever a change occurs in a component I manually run change detection using detectChanges.
If I set ChangeDetectionStrategy to OnPush on a…

Naveed Ahmed
- 10,048
- 12
- 46
- 85