我无法让我的AngularJS服务与ES6一起工作。这是超级简化,但我仍然无法使它工作!
代码不会抛出任何错误。
吉斯宾
// basic template
const template = '<h1>Super Bowl Quarterbacks (logged)</h1>';
// AppStore class
class AppStore {
constructor($log) {
this.$log = $log;
}
logName() {
this.$log.log('Tom Brady');
this.$log.log('Nick Foles');
}
}
// Controller class
class Controller {
constructor(AppStore) {
AppStore.logName();
}
}
// Component object
const component = {
bindings: {},
template: template,
// Per estus post, this solved my initial issue of not getting logging to work
controller: Controller
};
// app component
angular.module('app',[])
.component('app', component)
// Per estus post, this solved unknown provider error
.service('AppStore', AppStore);编辑:更新的代码和jsbin。我没有说明为了让它发挥作用而改变了什么。
发布于 2018-02-04 21:43:01
ES6糖化语法
const component = {
/*...*/
Controller
};是对应于ES5的
const component = {
/*...*/
Controller: Controller
};而组件应该具有controller属性。
它应该是:
const component = {
bindings: {},
template,
controller: Controller
};https://stackoverflow.com/questions/48612836
复制相似问题