Detect when input value changed in directive

You need to make an input property of input and then use the ngOnChanges hook to tell when the input property changes. @Directive({ selector: ‘[number]’ }) export class NumberDirective implements OnChanges { @Input() public number: any; @Input() public input: any; ngOnChanges(changes: SimpleChanges){ if(changes.input){ console.log(‘input changed’); } } } Plunkr Stackblitz

What is the difference between component and directive?

Basically there are three types of directives in Angular2 according to documentation. Component Structural directives Attribute directives Component It is also a type of directive with template,styles and logic part which is most famous type of directive among all in Angular2. In this type of directive you can use other directives whether it is custom … Read more

Make directive @Input required

Official solution As answered by Ryan Miglavs – smart usage of Angular’s selectors solves the issue. /** Note: requires the [a] attribute to be passed */ @Component({ selector: ‘my-dir[a]’, // <– use attribute selector along with tag to ensure both tag name and attribute are used to “select” element by Angular in DOM }); export … Read more

How to extend / inherit components?

Alternative Solution: This answer of Thierry Templier is an alternative way to get around the problem. After some questions with Thierry Templier, I came to the following working example that meets my expectations as an alternative to inheritance limitation mentioned in this question: 1 – Create custom decorator: export function CustomComponent(annotation: any) { return function … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)