带有tns平台声明的nativescript-carousel错误

时间:2019-03-05 22:18:15

标签: android angular typescript nativescript

我正在使用nativescript-carousel插件来构建nativescript轮播,但是当我执行tns build android时,出现此错误:

node_modules / nativescript-carousel / index.d.ts(1,22):错误TS6053:文件'D:/ Documents / coursera_examples / nativescript / VilcabambaHotel / node_modules / nativescript-carousel / node_modules / tns-platform-declarations /找不到android.d.ts。

我的home.component.html轮播是这样的:

@Lazy
@Repository
public class justAClassThatPerhapsCompiles{
    @Value("${app.my.prop}")
    String myProp; 

    @Lazy
    @Autowired
    Environment env;

    void justAFuncThatSomebodyWillTryToCompileMaybe(){
        env.getProperty("app.my.prop"); //env is null
        System.out.println(myProp); //myProp is null
    }
}

这是我的home.component.ts

    <GridLayout  horizontalAlignment="center" verticalAlignment="top" rows="*" columns="*" height="95%">        
    <Carousel #carousel ios:indicatorOffset="0,-10" ios:finite="true" ios:bounce="false" showIndicator="true" height="100%" indicatorAnimation="SWAP"
        indicatorColor="#66ccff" indicatorColorUnselected="#cceeff" height="250" width="80%">
        <CarouselItem backgroundColor="white" height="100%">
            <GridLayout *ngIf="cabin">
                <Image  [src]="BaseURL + cabin.image" ></Image>
            </GridLayout>
        </CarouselItem>
        <CarouselItem backgroundColor="white">
           <GridLayout *ngIf="house">
                <Image  [src]="BaseURL + house.image" ></Image>
            </GridLayout>
        </CarouselItem>
        <CarouselItem backgroundColor="white">
           <GridLayout *ngIf="ecoactivity">
                <Image  [src]="BaseURL + ecoactivity.image" ></Image>
            </GridLayout>
        </CarouselItem>
    </Carousel>
    </GridLayout>

如果我删除下一行代码,但轮播停止工作,该错误就会消失

从'nativescript-angular / element-registry'导入{registerElement}; 从“ nativescript-carousel”导入{Carousel,CarouselItem};

registerElement('Carousel',()=>轮播); registerElement('CarouselItem',()=> CarouselItem

我用下一行代码创建了一个名为reference.d.ts的文档,但错误仍然存​​在。

import { Component, OnInit, Inject, ChangeDetectorRef } from '@angular/core';

//import { TNSFontIconService } from 'nativescript-ngx-fonticon';
import { Page } from "ui/page";
import { View } from "ui/core/view";
import { SwipeGestureEventData, SwipeDirection } from "ui/gestures";
import * as enums from "ui/enums";

import { Cabin } from '../shared/cabin';
import { CabinService } from '../services/cabin.service';
import { House } from '../shared/house';
import { HouseService } from '../services/house.service';
import { Ecoactivity } from '../shared/ecoactivity';
import { EcoactivityService } from '../services/ecoactivity.service';
import { DrawerPage } from '../shared/drawer/drawer.page';



import { registerElement } from 'nativescript-angular/element-registry';
import { Carousel, CarouselItem } from 'nativescript-carousel';

registerElement('Carousel', () => Carousel);
registerElement('CarouselItem', () => CarouselItem);

@Component({
    selector: 'app-home',
    moduleId: module.id,
    templateUrl: './home.component.html',
    // styleUrls: ['./home.component.css']
})
export class HomeComponent extends DrawerPage implements OnInit {

    cabin: Cabin;
    house: House;
    ecoactivity: Ecoactivity;
    cabinErrMess: string;
    houseErrMess: string;
    ecoactivityErrMess: string;


    constructor(private cabinservice: CabinService,
        private houseservice: HouseService,
        private ecoactivityservice: EcoactivityService,
        private changeDetectorRef: ChangeDetectorRef,
        private page: Page,
       // private fonticon: TNSFontIconService,
        @Inject('BaseURL') private BaseURL) {
        super(changeDetectorRef);
    }

    ngOnInit() {
        this.cabinservice.getFeaturedCabin()
            .subscribe(cabin => this.cabin = cabin,
                errmess => this.cabinErrMess = <any>errmess);
        this.houseservice.getFeaturedHouse()
            .subscribe(house => this.house = house,
                errmess => this.houseErrMess = <any>errmess);
        this.ecoactivityservice.getFeaturedEcoactivity()
            .subscribe(ecoactivity => this.ecoactivity = ecoactivity,
                errmess => this.ecoactivityErrMess = <any>errmess);

    }

1 个答案:

答案 0 :(得分:1)

好像插件中的声明使用不当,您可以通过更新以下路径来手动调整它

/// <reference path="../tns-platform-declarations/android.d.ts" />

来自

/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

index.d.ts

编辑:

如果仍然发现任何其他TS错误,则只需在"skipLibCheck": true的{​​{1}}内添加compilerOptions