IONIC2 - SyntaxError: docs/file.js: Unexpected token (13:22) while parsing file: docs/file.js

IONIC2 - SyntaxError: docs/file.js: Unexpected token (13:22) while parsing file: docs/file.js

我正在将一个名为 Swiper-Angular2 的组件导入到我的 IONIC 2 项目中,但我收到一个奇怪的错误:

SyntaxError: docs/file.js: Unexpected token (13:22) while parsing file: docs/file.js

到目前为止,我的代码是:

page.js

import {Page} from 'ionic-angular';
import {Example1} from '../swiper/swiper';


@Page({ 
templateUrl: 'build/pages/home/home.html',
directives: [Example1]
})
export class HomePage {}

page.html

<ion-content>
<example1><example1>
</ion-content>

swiper.js

import {Component, ViewChild, AfterViewInit} from 'angular2/core';
import {KSSwiperContainer, KSSwiperSlide} from 'angular2-swiper';

@Component({
selector: 'example1',
pipes: [],
providers: [],
directives: [KSSwiperContainer, KSSwiperSlide],
template: require('./swiper.html')
})
//The error triggers here, exactly after "Example1"
export class Example1 implements AfterViewInit {

@ViewChild(KSSwiperContainer) swiperContainer: KSSwiperContainer;

example1SwipeOptions: any;

constructor() {
this.example1SwipeOptions = {
  slidesPerView: 4,
  loop: false,
  spaceBetween: 5
};
}

moveNext() {
this.swiperContainer.swiper.slideNext();
}

movePrev() {
this.swiperContainer.swiper.slidePrev();
}

ngAfterViewInit() {
console.log(this.swiperContainer);
}

}

Swiper.html

<div class="myslides">
<ks-swiper-container [options]="example1SwipeOptions">
<ks-swiper-slide *ngFor="#s of [1,2,3,4,5,6,7]">
<img src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
</ks-swiper-slide>
</ks-swiper-container>
<button (click)="movePrev()">Prev</button>
<button (click)="moveNext()">Next</button>
</div>

对导致问题的原因有什么想法吗?

看看这个:

https://forum.ionicframework.com/t/insert-swiper-slides-per-view-carousel-mode/50355

我相信你甚至不需要导入 Swiper;但是,您可以简单地使用它,因为它已经内置在 IONIC2 中。