【问题标题】:IONIC2 - SyntaxError: docs/file.js: Unexpected token (13:22) while parsing file: docs/file.jsIONIC2 - SyntaxError: docs/file.js: Unexpected token (13:22) while parsing file: docs/file.js
【发布时间】:2016-04-26 04:57:29
【问题描述】:

我正在将一个名为 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>

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

【问题讨论】:

  • 你在 Ionic2 项目中使用 ES6 吗?
  • 这个文件的内容是什么:docs/file.js?谢谢!
  • ES6已经有了,我在app.js中可以看得很清楚。 file.js == swiper.js

标签: angular ionic2 swiper


【解决方案1】:

看看这个:

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

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

【讨论】:

  • 非常感谢,我刚刚按照您提供的链接上的步骤操作,我已经解决了我的问题!
猜你喜欢
  • 2017-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-07
  • 2021-12-10
相关资源
最近更新 更多