Cordova 指令在离子3中不起作用

Cordova 指令在离子3中不起作用,cordova,ionic3,angular2-directives,Cordova,Ionic3,Angular2 Directives,离子3中的指令示例,以前使用的方法不起作用。 已经尝试了在ionic 2中实现指令的方式 import {Directive} from 'angular2/core'; @Directive({ selector: 'test', template: './test.html' )} export class MyDirective { } import {MyDirective } from './test' @Page({ templateUrl: '../page

离子3中的指令示例,以前使用的方法不起作用。 已经尝试了在ionic 2中实现指令的方式

import {Directive} from 'angular2/core';

@Directive({
   selector: 'test',
   template: './test.html'
)}
export class MyDirective { }

import {MyDirective } from './test'

@Page({
   templateUrl: '../page.html',
   directives: [MyDirective ],
})

这可以通过以下方式实现:

组件A,父组件

a组件.ts

import {Component} from '@angular/core';

@Component({
    selector: 'component-a',
    templateUrl: 'acomponent.html'
})
export class ComponentA { }
import {Component} from '@angular/core';

@Component({
    selector: 'component-b',
    templateUrl: 'bcomponent.html'
})
export class ComponentB { }
import { ComponentA } from 'pathto/acomponent';
import { ComponentB } from 'pathto/bcomponent';
//other imports here too

@NgModule({
  declarations: [
    ComponentA,
    ComponentB,
    //other declarations
  ],
  imports: [//your imports],
  bootstrap: [IonicApp],
  entryComponents: [
    ComponentA,
    ComponentB,
    //other entryComponents
  ],
  providers: [//your providers]
})
export class AppModule { }
acomponent.html

<div>
  <h3>Component A</h3>
  <component-b></component-b>
</div>
<h3>Component B</h3>
b组件.html

<div>
  <h3>Component A</h3>
  <component-b></component-b>
</div>
<h3>Component B</h3>
当您导航到
组件A
时,它将
组件B
注入选择器


希望这能有所帮助

这可以通过以下方式实现:

组件A,父组件

a组件.ts

import {Component} from '@angular/core';

@Component({
    selector: 'component-a',
    templateUrl: 'acomponent.html'
})
export class ComponentA { }
import {Component} from '@angular/core';

@Component({
    selector: 'component-b',
    templateUrl: 'bcomponent.html'
})
export class ComponentB { }
import { ComponentA } from 'pathto/acomponent';
import { ComponentB } from 'pathto/bcomponent';
//other imports here too

@NgModule({
  declarations: [
    ComponentA,
    ComponentB,
    //other declarations
  ],
  imports: [//your imports],
  bootstrap: [IonicApp],
  entryComponents: [
    ComponentA,
    ComponentB,
    //other entryComponents
  ],
  providers: [//your providers]
})
export class AppModule { }
acomponent.html

<div>
  <h3>Component A</h3>
  <component-b></component-b>
</div>
<h3>Component B</h3>
b组件.html

<div>
  <h3>Component A</h3>
  <component-b></component-b>
</div>
<h3>Component B</h3>
当您导航到
组件A
时,它将
组件B
注入选择器


希望这有帮助

请添加一些代码以便我们能看到发生了什么。添加@wesleycoetzeep请添加一些代码以便我们能看到发生了什么。添加@wesleycoetzee实际上我是爱奥尼亚的贝金纳。请同时建议家长和孩子的班级你所说的家长和孩子的班级是什么意思?我展示的解决方案,如果是一个完整的页面/组件,这里的AppProvider是什么?这是提供程序,即组件的服务。如果您的组件正在调用服务来进行http调用,则需要导入该组件。我需要在组件B中使用组件a。其中,在组件B的html中,我必须使用a的选择器标记,即,实际上,我是爱奥尼亚的贝金纳。请同时建议家长和孩子的班级你所说的家长和孩子的班级是什么意思?我展示的解决方案,如果是一个完整的页面/组件,这里的AppProvider是什么?这是提供程序,即组件的服务。如果您的组件正在调用服务来执行http调用,则需要导入该组件。我需要在组件B中使用组件a。在组件B的html中,我必须使用组件a的选择器标记,即。