【发布时间】:2016-09-23 17:28:32
【问题描述】:
我是 typescript 的新手,我正在尝试为 angular 2 指令创建一个函数。 谁能用 n00bs 的语言解释一下当我使用 Gulp 编译时错误试图告诉我什么?
不能在环境上下文中声明实现
该消息适用于offset() 和toggler()。
import { Directive, ElementRef, Input } from '@angular/core';
@Directive({
selector: 'offCanvas',
inputs: ['target', 'toggle', 'placement', 'autohide', 'recalc', 'disableScrolling', 'modal', 'canvas', 'exclude'],
host: {
'(click)': 'Click()'
}
})
export class OffCanvas {
@Input('target') target: string;
@Input('canvas') canvas: string;
@Input('state') state: string;
@Input('exclude') exclude: string;
@Input('placement') placement: string;
@Input('toggle') toggle: boolean;
@Input('autohide') autohide: boolean;
@Input('recalc') recalc: boolean;
@Input('disableScrolling') disableScrolling: boolean;
@Input('modal') modal: boolean;
public offset() {
switch (this.placement) {
case 'left':
case 'right': return (<HTMLElement>document.querySelector(this.target)).offsetWidth
case 'top':
case 'bottom': return (<HTMLElement>document.querySelector(this.target)).offsetHeight
}
}
public toggler() {
if (this.state === 'slide-in' || this.state === 'slide-out') return
this[this.state === 'slid' ? 'hide' : 'show']()
}
Click() {
this.toggler()
}
}
【问题讨论】:
标签: angular typescript directive