我有这样的指示 -
@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函数.这该怎么做 ?
mic*_*yks 13
@Directive({
selector: 'someDirective'
})
export class SomeDirective{
constructor() {}
render() {
console.log('hi from directive');
}
}
import {Component,ViewChild} from 'angular2/core';
import {SomeDirective} from '../../someDirective';
@Component({
templateUrl: '....tem.html',
directives: [SomeDirective]
})
export class SomeComponent {
@ViewChild(SomeDirective) vc:SomeDirective;
constructor(){}
ngAfterViewInit(){
this.vc.render();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16615 次 |
| 最近记录: |