如何在Scala.js中使用AngularJS的模块配置?

时间:2015-05-05 21:17:06

标签: javascript angularjs scala ionic scala.js

在纯JavaScript中,你可以这样做:

angular.module('mymodule', ['ionic'])
  .config(function($someParam1, $someParam2) {
    // do something with the parameters
}

我正在尝试使用Scala.js。我尝试了以下三次尝试,但都失败了:

尝试1:使用scalajs-angular

Angular.module("mymodule", Seq("ionic")).config(MyConf)

问题:MyConf必须扩展Config,我找不到任何可以传递参数的位置。

尝试2:使用scalajs-angulate

Angular.module("mymodule", Seq("ionic")).config((a: Any, b: Any) => {...})

应该有效,但我收到编译错误:not found: value js

尝试3:使用动态类型的API

global.angular.module("mymodule", Seq("ionic")).config((a: Any, b: Any) => {...})

编译,但{}内的内容不会被调用。

我现在能想到的唯一方法就是编写一个基于javascript的“Bridge”,其功能如下:

angular.module('mymodule', ['ionic']).config(function($a, $b) {
    com.example.myapp.MymoduleConfigurator.config($a, $b);
}

其中com.example.myapp.MymoduleConfigurator是用Scala编写的。

这是唯一的方法还是有更好的方法?

1 个答案:

答案 0 :(得分:0)

对于那些寻找这个问题的答案的人。 OP在GitHub上解决了问题,解决方法是添加以下导入:

import scalajs.js

另外,为了帮助您调试问题,您可以add flagsbuild.sbt文件,在编译时生成生成代码的日志到stdout,如下所示:

// print code for angulate's Module enhancements 
scalacOptions += "-Xmacro-settings:biz.enef.angulate.ModuleMacros.debug"

// print code generated for calls to module.controllerOf[]
scalacOptions += "-Xmacro-settings:biz.enef.angulate.ControllerMacros.debug"

// print code generated for calls to module.directiveOf[]
scalacOptions += "-Xmacro-settings:biz.enef.angulate.DirectiveMacros.debug"

// print code generated for calls to module.serviceOf[]
scalacOptions += "-Xmacro-settings:biz.enef.angulate.ServiceMacros.debug"

// print code generated for calls to module.componentOf[]
scalacOptions += "-Xmacro-settings:biz.enef.angulate.ComponentMacros.debug"

// print code generated for function DI
scalacOptions += "-Xmacro-settings:biz.enef.angulate.AnnotationMacros.debug"

// print code generated by angulate's HttpPromise extensions
scalacOptions += "-Xmacro-settings:biz.enef.angulate.HttpPromiseMacros.debug"

// enable logging of all registered services, controllers, and directives at run time
scalacOptions += "-Xmacro-settings:biz.enef.angulate.runtimeLogging"
相关问题