SET*_*SET 11 angularjs ecmascript-6
我想在Angular应用程序中使用ES6类并试图像这样使用它:
'use strict';
class EditorCtrl{
constructor(){
this.something = "ASd";
}
foo(){
}
}
angular.module('Editor').controller('EditorCtrl', EditorCtrl);
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,这段代码给了我一个错误:Class constructors cannot be invoked without 'new'
.为什么会发生这种情况以及如何解决这个问题?
Angular:1.4.7 Chrome:46.0.2490.71
小智 2
'use strict';
class EditorCtrl{
constructor($scope){
this.something = "ASd";
}
foo(){
}
}
// Use this instead.
angular.module('Editor').controller('EditorCtrl', ['$scope', function($scope) {
return new EditorCtrl($scope);
}]);
Run Code Online (Sandbox Code Playgroud)
由于错误通知必须返回“新”。这样注入也能起作用。干杯。
归档时间: |
|
查看次数: |
1854 次 |
最近记录: |