遗漏的类型错误:未定义是不是一个函数和未捕获的RangeError:最大调用堆栈大小超过Angular2

问题描述 投票:2回答:1

我一直在关注的Angular2 quicstart在学习Angular2框架的目的使用JavaScript ..我一直在做完全一样的准则告诉我,但我有一个错误

Uncaught TypeError: undefined is not a function angular2-all.umd.js:3528
Uncaught RangeError: Maximum call stack size exceeded angular2-polyfills.js:143

我不知道如果我错过了什么,这是我的应用程序的文件结构

  • 应用程序/ app.component.js boot.js
  • node_modules /
  • 的index.html
  • 的package.json

这就是基本代码

app.component.js

(function (app) {

    app.AppComponent = ng.core
        .Component({
            selector: 'my-app',
            template: '<h1>My First Angular 2 App</h1>'
        })
        .Class({
            constructor: function () {
            }
        });

})(window.app || (window.app == {}));

boot.js

(function(app) {

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

})(window.app || (window.app = {}));

的index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Angular 2</title>

    <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/app.component.js"></script>
    <script src="app/boot.js"></script>

</head>
<body>
    <my-app>Loading..</my-app>
</body>
</html>

我想,我也跟着快速启动完美,但我不知道在哪里我错过了,因为我是新来Angular2

javascript angular
1个回答
1
投票

你在你的代码变得几乎无法察觉错字,使一个巨大的差异。这是app.component.js文件的IIFE:

(function (app) {
    // ...
})(window.app || (window.app == {}));
// comparison operator ------^

请注意,您使用比较运算,而你想分配:

(function (app) {
    // ...
})(window.app || (window.app = {}));
© www.soinside.com 2019 - 2024. All rights reserved.