Generating then trying to use a simple directive isn;t working in Ionic 4
See original GitHub issueBug Report
Ionic Info
Run ionic info
from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.1.1 (/home/nmartin/npm/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.3
@angular-devkit/core : 0.7.4
@angular-devkit/schematics : 0.7.4
@angular/cli : 6.1.4
@ionic/ng-toolkit : 1.0.7
@ionic/schematics-angular : 1.0.5
System:
NodeJS : v10.6.0 (/usr/local/bin/node)
npm : 6.3.0
OS : Linux 4.18
Describe the Bug custom attribute Directives are not working in Ionic 4
Steps to Reproduce Steps to reproduce the behavior:
- run
ionic start myApp tabs --type=angular
- run
ionic g directive hilite
- edit hilite.directive.ts to look like:
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appHilite]',
})
export class HiliteDirective {
constructor(el: ElementRef) {
console.log('hilite!!!');
el.nativeElement.style.backgroundColor = 'yellow';
}
}
- edit app/home/homt.page.html to look like:
<p appHilite>If you get lost, the <a target="_blank" rel="noopener" href="https://ionicframework.com/docs">docs</a>
will be your guide.</p>
- run the app
Expected Behavior the paragraph to have a yellow background
Actual Behavior Nothing. Interestingly, If I move the directive injection from app.module.ts to home.module.ts, it works, BUT only in home.page.html, not any other page in the app, due to duplicate declarations
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Generating then trying to use a simple directive isn;t working ...
run ionic g directive hilite; edit hilite.directive.ts to look like: import { Directive, ElementRef } from '@angular/core'; @Directive({ ...
Read more >Directive not working in Ionic 4
Hello, I'm having a problem with directives in Ionic 4. I'm trying to make a simple directive that just outputs something with console.log....
Read more >Angular 4 / ionic 3 custom attribute directive not working
Hi I am trying to focus on a search input field. I have created a directive for that. It hs been exported from...
Read more >Using a Directive to Modify the Behaviour of an Ionic Component
In this tutorial, we are going to walk through how to modify the behaviour of the sliding item component in Ionic by creating...
Read more >Common errors and how to fix them - Mobiscroll Help Center
Runtime errors. 1. An interface may only extend a class or another interface. This error occurs when the Angular/Ionic application's typescript version is ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have also seen this - it seems that a custom directive will work if declared on a page which uses it directly or imported from a module on a page directly but NOT when it is declared in app.module.ts or imported as a module into app.module.ts … 😦 …
Current workaround is to put the directives into a common module and import that module into the pages where the directive is required. Not ideal but at least something.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.