10

In plain JavaScript you can do:

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

I am trying to do this with Scala.js. I tried the following three attempts, all of which failed:

Attempt 1: Use scalajs-angular

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

Problem: MyConf must extend Config and I did not find any location where I could pass in parameters.

Attempt 2: Use scalajs-angulate

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

This should work, but I get a compiler error: not found: value js

Attempt 3: Use the dynamically typed API

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

Compiles, but the content inside the {} does not get called.

The only way I can think of now is writing a javascript based "Bridge" which does something like:

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

where com.example.myapp.MymoduleConfigurator is written in Scala.

Is this the only way or is there a better approach?

rabejens
  • 7,594
  • 11
  • 56
  • 104
  • here is an example using scalajs-angular https://github.com/olivergg/scalajs-ionic-starttabs/blob/master/app-js/src/main/scala/com/olivergg/starttabs/IonicStartTabsApp.scala – invariant May 05 '15 at 23:22

1 Answers1

0

For those looking for answers to this question. It was resolved by the OP over on GitHub with the workaround being to add the following import:

import scalajs.js

Also, to aid in debugging your issues, you can add flags to your build.sbt file to generate a log of the generated code to stdout at compile time like so:

// 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"
Madness
  • 2,730
  • 3
  • 20
  • 29