简体   繁体   English

使用带有Ionic2 +打字稿的普通JS库

[英]Using a normal JS librarary with Ionic2 + typescript

I'm trying to use camanjs with my ionic2 + typescript project. 我正在尝试在我的ionic2 +打字稿项目中使用camanjs

I've also had a look at Ionic and Typings blog post by Mike , however it shows adding a library that is already in Typings 我也看过Mike的Ionic and Typings博客文章 ,但是它显示了添加一个已经在Typings中的库

Then I found this blog post from josh on adding goole maps that uses CDN method. 然后,我从josh找到了有关添加使用CDN方法的goole映射的博客文章

By following both of them I've done following so far, 到目前为止,通过关注这两个步骤,

added camanjs via CDN to the index.html file 通过CDN将camanjs添加到index.html文件

#index.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.js"></script>
<script src="cordova.js"></script>
...

Following is my ts file 以下是我的ts文件

#home.ts 
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';

declare var Camanjs: any;

@Component({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController) {
  }

  addFilter(){
     Camanjs("#image", function(){
       this.sinCity();
       this.render();
     })
  }
}

and my html file. 和我的html文件。 (when the user click the button I want to apply the filter) (当用户单击我要应用过滤器的按钮时)

#home.html
<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <button (click)="addFilter()">Filter</button>
  <img id='image' src="https://d339b5nop2tkmp.cloudfront.net/uploads/pet_photos/2016/7/13/469479_e76aa_340x340_af1c8.jpg">
</ion-content>

but when I click addFilter() I'm getting the following error 但是当我单击addFilter() ,出现以下错误

browser_adapter.js:84 ReferenceError: Camanjs is not defined
    at HomePage.addFilter (home.ts:14)
    at DebugAppView._View_HomePage0._handle_click_13_0 (HomePage.template.js:201)
    at view.js:375
    at dom_renderer.js:254
    at dom_events.js:27
    at ZoneDelegate.invoke (zone.js:323)
    at Object.onInvoke (ng_zone_impl.js:53)
    at ZoneDelegate.invoke (zone.js:322)
    at Zone.runGuarded (zone.js:230)
    at NgZoneImpl.runInnerGuarded (ng_zone_impl.js:86)

However I dont get any compiler errors via the IDE or in the compile time 😞, any help would be much appreciated. 但是我没有通过IDE或在编译时遇到任何编译器错误😞,我们将不胜感激。

Please note this the extended / more detailed version of my previous question 请注意,这是我上一个问题的扩展版本或更详细的版本

Instead of using Camanjs... try with this: 而不是使用Camanjs...尝试一下:

Caman('#my-image', function () {
  // ...
});

So replacing Camanjs by just Caman should allow you to call the methods on that library. 所以更换Camanjs由刚刚Caman应该让你调用该库中的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM