【发布时间】:2016-04-11 06:23:58
【问题描述】:
我想将ElementRef backToTopTarget 传递给指令.back-to-top。但是我无法使用ngOnChanges
<section #backToTopTarget>
<section class="back-to-top" [target]="backToTopTarget">
Back to top <i class="fa fa-angle-up"></i>
</section>
</section>
/// <reference path="../../../typings/angular2.d.ts" />
import {Directive, Input, OnChanges, ElementRef} from 'angular2/core';
import {BaseComponent} from "../../BaseComponent/BaseComponent";
@Directive({
selector: '.back-to-top',
})
export class BackToTop implements OnChanges {
private $el;
@Input('target') private target;
private $target;
constructor(private el: ElementRef) {
this.$el = $(this.el.nativeElement);
}
ngOnChanges({target}) {
// target.currentValue === undefined
}
}
所以我不能或我做错了什么?
【问题讨论】:
标签: angularjs-directive angular syntactic-sugar