Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular2显示数据示例不工作_Javascript_Html_Angularjs_Angular_Angular2 Template - Fatal编程技术网

Javascript Angular2显示数据示例不工作

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 --> <!

我正在学习Angular2的教程,但它对我不起作用。让我知道我错过了什么

顺便说一句,我只使用ES5

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";
    }
  });