Angular 2 - ' get'访问者必须返回一个值

时间:2016-09-16 17:13:31

标签: jquery angular typescript carousel

我是Angular 2的新手。目前,我正试图在Angular 2中构建幻灯片轮播组件,并且我试图使用来自here的ng2-bootstrap轮播。< / p>

这是我目前在 carousel.component.ts 中所拥有的:

import {Component, OnInit, OnDestroy, ViewEncapsulation, Input, HostBinding} from '@angular/core';
import { Router } from '@angular/router';
import {Project} from './project';
import {ProjectService} from './project.service';
import { CarouselModule } from 'ng2-bootstrap/components/carousel';

@Component({
    selector: 'carousel',
    encapsulation: ViewEncapsulation.None,
    providers: [ProjectService],
    templateUrl: 'app/carousel.html'
 })
  //Template for the tag

export class CarouselComponent implements OnInit {
  errorMessage: string;
    projects: Project[];
  selectedProject: Project;
  private start = false;
    public length = Number;
  @Input() private noWrap:boolean;
  @Input() private noPause:boolean;
  @Input() private noTransition:boolean;
  @Input() public get interval():number {};

    constructor(
    private router: Router,
    private projectService: ProjectService){
     }

   getProjects() {
      this.projectService.getProjects()
        .subscribe(
              projects => this.projects = projects,
              error =>  this.errorMessage = <any>error
              );
      }

  ngOnInit(){
        this.getProjects();
    }

}

// class Slide implements OnInit, OnDestroy
@Component({
  selector: 'slide'
})
export class SlideComponent {
  @Input() public index:number;

  @HostBinding('class.active')
  @Input() public active:boolean;

  @HostBinding('class.item')
  @HostBinding('class.carousel-item')
  private addClass:boolean = true;
}

但是当我运行它时,我收到错误app/carousel.component.ts(24,23): error TS2378: A 'get' accessor must return a value.我不知道如何纠正,因为我基本上只是从教程中复制了解决方案。

间隔的值在文件 app.component.ts 中给出 像:

public interval:number = 5000;
    public noWrapSlides:boolean = false;
    public slides:Array<any> = [];

我使用的是Angular 2 2.0.0-rc.4 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

以下行似乎有误:

  @Input() public get interval():number {};

输入怎么是吸气剂?