0

我是 angular 2.0.0 beta 的新手,并且使用 javascript 进行开发。我无法使 ngFor 指令正常工作。我有一个组件 list.component.js、一个 boot.js 文件和 index.html。我不知道我做错了什么。以下是代码:

list.component.js

function(app) {
  app.ListComponent = ng.core
    .Component({
        selector: 'list'
    })
    .View({
        template:'<ul>'
        +'<li *ng-for="#name of names" >{{name}}</li>'
        +'</ul>'
        +'<p *ng-if="names.length > 3">You have many friends!</p>',
        directives: [angular.NgFor]
    })
    .Class({
        constructor: function() {
            this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];
        }
    });
})(window.app || (window.app = {}));

引导.js

(function(app) {
  document.addEventListener('DOMContentLoaded', function() {
    ng.platform.browser.bootstrap(app.ListComponent);
  });
})(window.app || (window.app = {}));

索引.html

<html>
  <head>
    <title>Angular 2 Example</title>

    <!-- 1. Load libraries -->
    <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>

    <!-- 2. Load our 'modules' -->
    <script src='app/list.component.js'></script>
    <script src='app/boot.js'></script>

  </head>

  <!-- 3. Display the application -->
  <body>
    <list>loading...</list>
  </body>

</html>

我所看到的只是“正在加载...”。

angular.io 上 javascript 的 angular2 beta 文档似乎也有限。如果有人可以参考一些关于 javascript 的 angular 2 beta 的好教程,那将非常有帮助。谢谢。

4

0 回答 0