gpt4 book ai didi

javascript - AngularJs2 'angular not defined' 启动指南后出现错误

转载 作者:行者123 更新时间:2023-11-28 06:37:23 24 4
gpt4 key购买 nike

我按照 their quickstart 开始使用 AngularJs 2

到目前为止一直运行良好。

现在我已经转到他们的 displaying data指导但我被卡住了,这一点。我正在使用 ES5。

索引:

<!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-stuff></display-stuff>
</body>
</html>

display.js:

function DisplayComponent()
{
this.myOwnVar = 'Chicki chicki Gabriel';
}

DisplayComponent.annotations = [
new angular.ComponentAnnotation({
selector: 'display'
}),
new angular.ViewAnnotation({
template:
'<p>My name is, hi, my name is who, my name is: {{ myOwnVar }}</p>'
})
];

它说 Angular 没有定义,我认为是这样,因为上一个教程中的 app.js 工作得很好:

(function() {
var AppComponent = ng
.Component({
selector: 'my-app',
template: '<h1>My first Template audited gf</h1>'
})
.Class({
constructor: function() {

}
});

document.addEventListener('DOMContentLoaded', function() {
ng.bootstrap(AppComponent);
});
})();

最佳答案

有关工作示例,请参阅 https://gist.github.com/lokanx/6bc34b10bbe9cd7c2d59 .

显示.js

(function () {
var Display = ng.Component({
selector: 'display',
templateUrl: 'views/display.html',
directives: [ng.NgFor, ng.NgIf],
providers: [Display]
})
.Class({
constructor: function () {
this.myName = "Alice";
this.names = ["Aarav", "Martín", "Shannon"];
}
});

ng.provide("Display", Display);
})();

和app.js

(function () {
var AppComponent = ng.Component({
selector: 'my-app',
templateUrl: 'views/app.html',
directives: [Display]
})
.Class({
constructor: function () {}
});

document.addEventListener('DOMContentLoaded', function () {
ng.bootstrap(AppComponent);
});

})();

app.html

 <h1>My First Angular 2 App </h1>
<display></display>

显示.html

<p>My name: {{ myName }}</p>

我可以建议你开始用 typescript 编写 Angular2 代码吗?容易多了。

关于javascript - AngularJs2 'angular not defined' 启动指南后出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34155203/

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