为什么我在刚刚启动的Angular2应用程序中收到此错误?

时间:2016-12-26 05:02:01

标签: angular

我刚开始编写一个我从中克隆的新的angular2应用程序 https://github.com/angular/quickstart

为什么我收到此错误?

  

app / app.component.ts(8,3):错误TS2345:类型'{moduleId:   串; selector:string; templateUrl:string;指令:string [];   }'不能分配给'Component'类型的参数。宾语   literal只能指定已知属性,而'directives'则不能   存在于“组件”类型中。

app.component.ts

import { Component } from '@angular/core';
import { NavbarComponent } from './components/navbar/navbar.component';

@Component({
  moduleId: module.id,
  selector: 'my-app',
  templateUrl: 'app.component.html',
  directives: [NavbarComponent]
})
export class AppComponent  {  }

navbar-component.ts

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'navbar',
  templateUrl: `navbar.component.html`,
})
export class NavbarComponent  {  }

1 个答案:

答案 0 :(得分:6)

app.component.ts

中删除以下行
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x

if (document.attachEvent) //if IE (and Opera depending on user setting)
    document.attachEvent("on"+mousewheelevt, function(e){alert('Mouse wheel movement detected!')})
else if (document.addEventListener) //WC3 browsers
    document.addEventListener(mousewheelevt, function(e){alert('Mouse wheel movement detected!')}, false)

并将其添加到 app.module.ts

directives: [NavbarComponent]

指令不再可用于2.0.0-rc.6