[英]Angular 5 with es5
Angular 4支持以下语法
var HelloComponent = ng.core
Component({
selector: 'hello-cmp',
template: 'Hello World!',
viewProviders: [Service]
.Class({
constructor: [Service, function (service) {
},`
});
在Angular 5中,Class缺少任何人都可以使用ES5语法提供Angular 5,目前我无法切换ES6所以请避免使用该建议。 如果切换到ES6是唯一的方法,那么我将坚持到现在的角度4
您需要在组件
类
函数上使用静态属性annotations
和parameters
,如下所示:
function Service() {}
function AppComponent(service) {
console.log(service);
}
AppComponent.prototype.ngOnInit = function() {
console.log('test ngOnInit');
};
AppComponent.annotations = [
new Component({
selector: 'my-app',
template: '<h1>Example of Angular 5.0.5 in ES5</h1>',
viewProviders: [Service]
})
];
AppComponent.parameters = [ Service ];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.