相关疑难解决方法(0)

Angular 2:获取对组件中使用的指令的引用

我有一个组件,其模板看起来像这样:

<div [my-custom-directive]>Some content here</div>
Run Code Online (Sandbox Code Playgroud)

我需要访问此处使用的MyCustomDirective类实例.当我想要访问子组件时,我使用ng.core.ViewChild查询.是否有相同的功能来访问子指令?

angular-template angular2-directives angular

58
推荐指数
3
解决办法
4万
查看次数

Angular 2 - 如何访问指令并在其中调用成员函数

我有这样的指示 -

@Directive({
    selector:   'someDirective'
})
export class  SomeDirective{         
    constructor() {}    
    render = function() {}
}
Run Code Online (Sandbox Code Playgroud)

然后我导入指令

import {SomeDirective} from '../../someDirective';
@Page({
    templateUrl: '....tem.html',
    directives: [SomeDirective]
})
export class SomeComponent {
      constructor(){}
      ngAfterViewInit(){//want to call the render function in the directive
}
Run Code Online (Sandbox Code Playgroud)

在ngAfterViewInit中,我想在指令中调用render函数.这该怎么做 ?

ionic2 angular

9
推荐指数
1
解决办法
2万
查看次数