0
我想在我的ScalaJs Angular指令中使用外部JavaScript插件。 我不知道這樣做的最佳方式,所以目前我將此功能添加到window
。Scalajs + Angularjs如何使用外部JavaScript插件
的JavaScript插件看起來是這樣的:
(function(){
"use strict";
SmartCrop.crop = function() {
//some function
}
SmartCrop.options = {
//options
}
//...
window.SmartCrop = SmartCrop // I added this line
})()
但我不知道怎麼在我的scalaJs代碼訪問window.SmartCrop。
我試圖做的是,在我的指導,但沒有成功(請看看我下面的代碼寫的註釋):
@JSExport
@injectable("smartCrop")
class SmartCropDirective(window: Window) extends ElementDirective with TemplatedDirective {
override val templateUrl = "assets/templates/smartcrop/smartcrop.html"
override def link(scope: ScopeType, elements: Seq[Element], attrs: Attributes): Unit = {
// I can found window.SmartCrop in my console if I log window
console.log(window)
// this line is not working but I'm looking for something similar:
window.SmartCrop.crop()
}
}
所以,我在找的好辦法使用這個插件。