gpt4 book ai didi

javascript - Angular 2 中的 For 循环抛出异常

转载 作者:行者123 更新时间:2023-12-02 15:19:43 24 4
gpt4 key购买 nike

我已经按照 quickstart 设置了 Bootstrap .

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>

显示.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 循环,它会再次工作并正常显示第一个变量,所以我猜它是一个语法错误,但它似乎与 documentation

最佳答案

注意:我无法对这篇完整的帖子发表评论。

您使用的是哪个版本的 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>

关于javascript - Angular 2 中的 For 循环抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34175007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com