Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49215

Ionic 3 declare a global directive

$
0
0

@opahopa wrote:

greetings.
i have a simple directive like

@Directive({
  selector: '[auth-protected-click]'
})
export class AuthProtectedClickDirective {

  constructor() {
    console.log('fgfgfgfgfgfgfg')
  }

  @HostListener('click', ['$event']) onClick($event){
    console.info('clicked: ' + $event);
  }
}

How can i declare it in app.module.ts to make it accessible globally?

tried:

  1. declare it as module
@NgModule({
  declarations: [
    AuthProtectedClickDirective,
  ],
  exports: [
    AuthProtectedClickDirective
  ]
})
export class AuthProtectedClickDirectiveModule {}

and input in app.module. @NgModule => imports. this doesn’t throw any errors, but directive isn’t working (not initialized).

  1. input in app.module. @NgModule => decralations (not as module, but as AuthProtectedClickDirective). Result is the same - no errors and not initialized.

The only way i can use it is adding a dependency to this directive / it’s module directly in the *page*.module, which i don’t really want to do because planning to use it in multiple pages.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>