【问题标题】:angular2 ReferenceError: angular is not defined new angular.Component({angular2 ReferenceError: 角度未定义新的 angular.Component({
【发布时间】:2019-10-02 22:11:04
【问题描述】:

我开始看 angular2, 但是有了这个简单的代码

<html>
    <head>
            <script src="https://code.angularjs.org/2.0.0-alpha.19/angular2.sfx.dev.js"></script>
            <script>
            function AppComponent() {}

            AppComponent.annotations = [
                new angular.Component({
                        selector: 'my-app'
                }),
                new angular.View({
                        template: '<h1>My first Angular 2 App</h1>'
                })
            ];

            document.addEventListener('DOMContentLoaded', function() {
              angular.bootstrap(AppComponent);
            });
            </script>
    </head>
    <body>
        <my-app></my-app>
    </body>
</html>

我有以下错误:

SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function function onGlobalPostMessage(event) {

ReferenceError: angular is not defined new angular.Component({

【问题讨论】:

    标签: angular


    【解决方案1】:

    我假设您在 FireFox 中运行它? Chrome 似乎没有问题。

    问题是编译的 Angular 里面有错误。如果您想继续在 FireFox 中工作,请下载 angular2.sfx.dev.js 并从中修改第 5610 行:

    function onGlobalPostMessage(event) {
    

    到这里:

    var onGlobalPostMessage = function(event) {
    

    这应该让你再次工作。

    我建议使用alpha.21 which is out now,顺便说一句,或者您可以使用alpha.20 which is compiled here。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多