【发布时间】:2017-10-27 15:07:26
【问题描述】:
我正在尝试将 Angular js 服务用作 ES6 类。但出现错误。
没有'new'就不能调用类构造函数BaseService。
这是服务代码。
"use babel";
(function() {
'use strict';
class BaseService {
constructor() {
this.data = {
items: []
};
}
loadData() {
this.data.items = ['one', 'two', 'three'];
}
}
angular.module('app').service('BaseService', BaseService);
}());
这是我正在尝试的链接。 https://embed.plnkr.co/D9MEJZe4pF6oztf7DP31/
【问题讨论】:
-
你的问题是什么?
-
我的问题是为什么我上面的代码给出了错误类构造函数 BaseService 不能在没有'new'的情况下被调用我包括索引.html 中的基本服务。请参阅embed.plnkr.co/D9MEJZe4pF6oztf7DP31 以获取不起作用的完整代码。感谢您的回复。
标签: javascript angularjs ecmascript-6