【发布时间】:2016-04-26 11:23:43
【问题描述】:
我正在声明一个非常简单的角度组件,如下所示:
import htmlTemplate from './searchInput.html'
export default class SearchInput {
constructor() {
this.template = htmlTemplate;
}
}
然后我像这样使用它:
import SearchInput from './components/searchInput/searchInput';
angular.module('prj', [])
.component('searchInput', new SearchInput());
效果很好。
但是到目前为止,我发现的所有带有 angular 1.x 和 ECMA 6 的示例都没有在 SearchInput 类上调用 new。如果我省略new,则不会加载模板。
如果我希望能够将我的代码更改为(没有新的),
angular.module('prj', [])
.component('searchInput', SearchInput());
我需要改变什么?
【问题讨论】:
-
试过 Reflect.construct('SearchInput', '') ?
-
我应该把它放在哪里,它应该做什么?
-
.component('searchInput', Reflect.construct('SearchInput', ''));试试看
-
.component需要一个对象。我不知道你为什么要首先声明一个“类”。 -
这是为
controller和service完成的,因为它们需要一个构造函数,以及在许多其他示例中。component需要一个对象,而不是构造函数。
标签: javascript angularjs ecmascript-6