【发布时间】:2017-02-12 13:14:38
【问题描述】:
我将$timeout 注入到以下指令中,但它没有定义。
以下代码将undefined打印到控制台并抛出TypeError: $timeout is not a function;
export default class foo {
constructor ($timeout) {
'ngInject';
this.restrict = 'A';
this.scope = {};
this.$timeout = $timeout;
console.log( $timeout );
$timeout( function() {
alert('timeout');
}, 0 );
}
link($scope, $element, $attrs, $ctrl ) {
....
}
// Create an instance so that we can access this inside link
static factory() {
foo.instance = new foo();
return foo.instance;
}
}
【问题讨论】:
标签: javascript angularjs angularjs-directive ecmascript-6 angularjs-timeout