Javascript Angular2显示数据示例不工作
我正在学习Angular2的教程,但它对我不起作用。让我知道我错过了什么 顺便说一句,我只使用ES5 在Javascript Angular2显示数据示例不工作,javascript,html,angularjs,angular,angular2-template,Javascript,Html,Angularjs,Angular,Angular2 Template,我正在学习Angular2的教程,但它对我不起作用。让我知道我错过了什么 顺便说一句,我只使用ES5 在index.html中编码- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Angular2 Demo</title> <!-- 1. Load libraries --> <!
index.html中编码-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular2 Demo</title>
<!-- 1. Load libraries -->
<!-- IE required polyfill -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/rxjs/bundles/Rx.umd.js"></script>
<script src="node_modules/angular2/bundles/angular2-all.umd.js"></script>
<script src="app/component.js"></script>
</head>
<body>
<display></display>
</body>
</html>
在浏览器中运行idex.html时出现的错误-
参考错误:角度未定义样本似乎不正确。。。您应该使用ComponentMetadata
和viewmatadata
对象:
function DisplayComponent() {
this.myName = "Alice";
}
DisplayComponent.annotations = [
new ng.core.ComponentMetadata({
selector: "display"
}),
new ng.core.ViewMetadata({
template:
'<p>My name: {{ myName }}</p>'
})
];
请参阅以下链接:
此链接可以为您提供一些提示:
- 更好的ES5代码用于角度2-
如果文档不正确,我应该遵循什么?有什么帮助吗?:)我用更多的样本更新了我的答案。也许是文件中的打字错误。帕斯卡·普雷希特的文章可能是一个很好的起点;-)谢谢链接,抱歉出去喝咖啡了:)不用担心;-)事实上,将ES5与Angular2结合使用的方法正在进行中。这就是为什么关于这个主题的文档较少,但Angular2的人正在研究这个。。。
function DisplayComponent() {
this.myName = "Alice";
}
DisplayComponent.annotations = [
new ng.core.ComponentMetadata({
selector: "display"
}),
new ng.core.ViewMetadata({
template:
'<p>My name: {{ myName }}</p>'
})
];
var DisplayComponent = ng.core.
Component({
selector: "display"
})
.View({
template:
'<p>My name: {{ myName }}</p>'
})
.Class({
constructor: function() {
this.myName = "Alice";
}
});