需要学习角2的TypeScript吗?
角2可以和普通JavaScript一起使用吗?
编辑:我已经看到作为ES6、ES7、Dart使用的语言被编译成要执行的JavaScript,但是我还没有看到任何直接使用ES5 JavaScript的引用。
发布于 2015-06-07 01:22:05
可以,停那儿吧。
去读这个指南吧。按下代码示例上的ES5选项卡将显示与TypeScript相关联的常规ES5 JavaScript。
然而,由于明显的原因,API预览是不完整的。因此,您可能还没有找到其中列出的ES5方法,其中一些方法在发布前可能会更改。
ES5中角2.0主要部件的当前示例。
function AppComponent() {}
AppComponent.annotations = [
new angular.ComponentAnnotation({
selector: 'my-app'
}),
new angular.ViewAnnotation({
template: '<h1>My first Angular 2 App</h1>'
})
];
document.addEventListener('DOMContentLoaded', function() {
angular.bootstrap(AppComponent);
});发布于 2015-12-16 03:48:26
是。
下面是两个简单的组件,它们以不同的方式编写,在用JavaScript (EcmaScript 5)编写时,角2支持这些组件:
(function() {
var HelloWorldComponent = function() {};
HelloWorldComponent.annotations = [
new ng.core.Component({
selector: 'hello-world',
template: '<h1>Hello Angular2!</h1>'
})
];
var HelloFlentApi = ng.core.Component({
selector: 'hello-fluent',
template: '<h1>Hello {{name}}!</h1>' + '<input [(ngModel)]="name">',
}).Class({
constructor: function() {
this.name = "Fluent API";
}
});
var AppComponent = ng.core.Component({
selector: 'company-app',
template: '<hello-world></hello-world>' +
'<hello-fluent></hello-fluent>',
directives: [HelloWorldComponent, HelloFlentApi]
}).Class({
constructor: function() {}
});
document.addEventListener("DOMContentLoaded", function() {
ng.platform.browser.bootstrap(AppComponent);
});
}());<script src="https://code.angularjs.org/2.0.0-beta.0/Rx.umd.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-all.umd.dev.js"></script>
<company-app>
Loading ...
</company-app>
我在这里详细解释了代码:
在今天的Angular2 (ES5) -Beta0版中编写一个JavaScript组件
正如链接所述,这适用于角质2 Beta 0,它是几个小时前在撰写此答案时发布的。
发布于 2016-01-05 19:14:55
编写普通javascript es5组件的简单方法:
(function() {
var MyComponent = ng.
Component({
selector: 'my-component'
})
.View({
templateUrl: 'my-component.html'
})
.Class({
constructor: function () {
this.someArray = [];
},
someCustomFunction: function(item) {
this.someArray.push(item);
...
}
})
document.addEventListener('DOMContentLoaded', function() {
ng.bootstrap(MyComponent);
});
})();下面是一个使用Javascript es5的简单es5。
https://stackoverflow.com/questions/30689094
复制相似问题