对于角度为2的循环抛出异常

For Loop in angular 2 throws Exception

本文关键字:循环 抛出异常 于角度      更新时间:2023-09-26

我已经按照快速启动设置了一个引导程序。

index.html

<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>Angular 2 Quickstart</title>
        <!-- Angular is working on removing the traceur dependency -->
        <script src="node_modules/angular2/bundles/angular2.sfx.dev.js"></script>
        <script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>
        <script src="app.js"></script>
        <script src="components/display.js"></script>
    </head>
    <body>
        <my-app></my-app>
        <display></display>
    </body>
</html>

display.js

function DisplayComponent() {
    this.myName = "Jim";
    this.trophies = 'laugh';
    this.dogs = ['this','is','it'];
}
DisplayComponent.annotations = [
    new ng.ComponentMetadata({
        selector: "display"
    }),
    new ng.ViewMetadata({
        template:
            '<input [(ng-model)]="myName" type="text">' +
            '<h2>{{ trophies }}</h2>' +
            '<p>name: {{ myName }}</p>' +
            '' +
            '<ul>' +
            '   <li *ng-for="#dog of dogs">' +
            '       {{ dog }}' +
            '   </li>' +
            '</ul>',
        directives : [ng.FORM_DIRECTIVES]
    })
];
document.addEventListener('DOMContentLoaded', function() {
    ng.bootstrap(DisplayComponent);
});

出于某种原因,如果我删除For循环,它会再次工作并正常显示第一个变量,所以我猜这是一个语法错误,但它似乎与文档

注意:我对这篇完整的文章感到抱歉。

您使用的是哪种类型的angular?因为以下东西对我有效:

<head lang="en">
    <meta charset="UTF-8">
    <title>Angular 2 Quickstart</title>
    <!-- Angular is working on removing the traceur dependency -->
    <script src="https://code.angularjs.org/2.0.0-alpha.47/angular2.sfx.dev.js"></script>
    <script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>
    <script src="display.js"></script>
</head>
<body>
    <display></display>
</body>