Angular 2教程快速入门不加载组件

时间:2016-12-12 02:58:44

标签: angular

我开始学习Angular,因此想要做他们的教程。 但是,它只是不加载组件。 我做到了这一点:

  1. git clone https://github.com/angular/quickstart.git quickstart
  2. cd quickstart
  3. npm install
  4. npm start
  5. 我还没有修改代码,安装运行正常,没有任何错误。 但是,在启动应用程序时,浏览器只显示“在此处加载AppComponent内容...”而不是预期的“Hello Angular”。 浏览器控制台给出了以下错误:

    Error: (SystemJS) in strict mode code, functions may be declared only at top level or immediately within another function
        ZoneDelegate.prototype.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:229:17
        Zone.prototype.run@http://localhost:3000/node_modules/zone.js/dist/zone.js:113:24
        scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:509:52
        ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:262:21
        Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:151:28
        drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:405:25
        ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:336:25
    
        Evaluating http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js
        Error loading http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js as "@angular/compiler" from http://localhost:3000/node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js
    
    
    var error = NativeError.apply(this, arguments);
    

    app.component.ts

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'my-app',
      template: `<h1>Hello {{name}}</h1>`,
    })
    export class AppComponent  { name = 'Angular'; }
    

    app.module.ts

    import { NgModule }      from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { AppComponent }  from './app.component';
    
    @NgModule({
      imports:      [ BrowserModule ],
      declarations: [ AppComponent ],
      bootstrap:    [ AppComponent ]
    })
    export class AppModule { }
    

    的package.json

    {
      "name": "angular-quickstart",
      "version": "1.0.0",
      "description": "QuickStart package.json from the documentation, supplemented with testing support",
      "scripts": {
        "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
        "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
        "lint": "tslint ./app/**/*.ts -t verbose",
        "lite": "lite-server",
        "pree2e": "webdriver-manager update",
        "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
        "test-once": "tsc && karma start karma.conf.js --single-run",
        "tsc": "tsc",
        "tsc:w": "tsc -w"
      },
      "keywords": [],
      "author": "",
      "license": "MIT",
      "dependencies": {
        "@angular/common": "~2.3.0",
        "@angular/compiler": "~2.3.0",
        "@angular/core": "~2.3.0",
        "@angular/forms": "~2.3.0",
        "@angular/http": "~2.3.0",
        "@angular/platform-browser": "~2.3.0",
        "@angular/platform-browser-dynamic": "~2.3.0",
        "@angular/router": "~3.3.0",
    
        "angular-in-memory-web-api": "~0.1.17",
        "systemjs": "0.19.40",
        "core-js": "^2.4.1",
        "reflect-metadata": "^0.1.8",
        "rxjs": "5.0.0-rc.4",
        "zone.js": "^0.7.2"
      },
      "devDependencies": {
        "concurrently": "^3.1.0",
        "lite-server": "^2.2.2",
        "typescript": "~2.0.10",
    
        "canonical-path": "0.0.2",
        "http-server": "^0.9.0",
        "tslint": "^3.15.1",
        "lodash": "^4.16.4",
        "jasmine-core": "~2.4.1",
        "karma": "^1.3.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-jasmine": "^1.0.2",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "4.0.9",
        "webdriver-manager": "10.2.5",
        "rimraf": "^2.5.4",
    
        "@types/node": "^6.0.46",
        "@types/jasmine": "^2.5.36",
        "@types/selenium-webdriver": "^2.53.33"
      },
      "repository": {}
    }
    

2 个答案:

答案 0 :(得分:1)

我有同样的问题,我发现了这个: angular2 quickstart ReferenceError: angular is not defined new angular.Component({

似乎这是Firefox浏览器的一个问题,Chrome没有问题......

答案 1 :(得分:0)

我有同样的问题,我修复了: 安装angular2@2.0.0-beta.21 并卸载出现错误的组件,如zone.js,core.js,清理缓存,并重新安装它们和systemjs。

当您卸载zone.js时,您从浏览器的控制台和cmd日志中获得的错误可以在下一步中引导您或多或少。

相关问题