【问题标题】:angular 2 example error角度 2 示例错误
【发布时间】:2016-11-20 07:54:46
【问题描述】:

我在运行我的 Angular 2 应用程序时遇到错误,这是我的 app.js

import 'zone.js/lib/browser/zone-microtask';
import 'reflect-metadata';

import { Component, View, bootstrap } from 'angular2/angular2';
import { HelloComponent } from './hello.component';

@Component({
  selector: 'hello-app'
})
@View({
  directives: [HelloComponent],
  template: `
    <div>
      <hello-component></hello-component>
    </div>
  `
})
class HelloApp { }

bootstrap(HelloApp, []);

这是错误:

{ [SyntaxError: /code/angular2-example/app.js: Unexpected token (7:0) 解析文件时:/code/angular2-example/app.js] pos: 190, loc: 位置 { line: 7, column: 0 }, _babel: true, codeFrame: '\u001b[0m 5 | \u001b[36m进口\u001b[39m \u001b[32m{\u001b[39m HelloComponent \u001b[32m}\u001b[39m 从 \u001b[31m\'./hello.component\'\u001b[39m\u001b[1m;\u001b[22m\n 6 | \n> 7 | \u001b[7m@\u001b[27m组件\u001b[34m\u001b[1m(\u001b[22m\u001b[39m\u001b[32m{\u001b[39m\n | ^\n 8 |选择器\u001b[1m:\u001b[22m \u001b[31m\'hello-app\'\u001b[39m\n 9 | \u001b[32m}\u001b[39m\u001b[34m\u001b[1m]\u001b[22m\u001b[39m\n 10 | \u001b[7m@\u001b[27m查看\u001b[34m\u001b[1m(\u001b[22m\u001b[39m\u001b[32m{\u001b[39m\u001b[0m', 文件名:'code/angular2-example/app.js',

但我没看到。请你帮帮我。我只是从角度 2 开始。

【问题讨论】:

  • 您使用的是哪个 Angular2 版本? @View() 几个月前被删除。还有来自zone-microtask 和reflect-metadata 的导入应该做什么?
  • 最新更新的进口清单见stackoverflow.com/a/34697758/5043867

标签: angular browserify babeljs


【解决方案1】:

你的导入语句是错误的!

   import { Component, View, bootstrap } from 'angular2/angular2';

从“@angular/core”导入

   import {Component} from '@angular/core';
   import (bootstrap) from 'angular2/platform.browser';

组件从angular/core导入,View不再是angular中的类

【讨论】:

猜你喜欢
  • 2016-03-22
  • 2016-05-26
  • 2016-08-19
  • 2017-12-06
  • 2023-03-04
  • 2018-12-31
  • 2023-03-29
  • 1970-01-01
  • 2016-12-23
相关资源
最近更新 更多