Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct handling of Directive controllers #29

Closed
jokade opened this issue Feb 5, 2015 · 1 comment
Closed

Correct handling of Directive controllers #29

jokade opened this issue Feb 5, 2015 · 1 comment
Assignees
Milestone

Comments

@jokade
Copy link
Owner

jokade commented Feb 5, 2015

Controllers for Directives must be handled differently than normal controllers:
for a controller defined on a directive angular creates a empty object which is then passed as thisto the controller constructor; every directive defined on a tag then may add members to the passed in this.
The current (0.1) implementation does not handle this correctly (see discussion on on issue #28).

@jokade jokade added the bug label Feb 5, 2015
@jokade jokade self-assigned this Feb 5, 2015
@jokade jokade added this to the v0.2 milestone Feb 5, 2015
@jokade
Copy link
Owner Author

jokade commented Feb 5, 2015

Solution: use controller function and define controller as a facade trait instead of a Scala class;

Remodelled Directive API:

trait MyDirectiveCtrl extends js.Object {
  var click() : js.Function = js.native
}

class MyDirective {
  override type ControllerType = MyDirectiveCtrl
  override type ScopeType = js.Dynamic
  override val controllerAs = "ctrl"

  override val isolateScope = js.Dictionary(
    "foo" -> "=bar"
  }

  override def controller(ctrl: ControllerType, scope: ScopeType, elem: JQLite, attrs: Attributes) : Unit = {
    ctrl.click() = () => {
      /* ... */
    }
  }

  override def postLink(scope: ScopeType, element: JQLite, attrs: Attributes, ctrl: ControllerType): Unit = {
     /* ... */
  } 
}

jokade added a commit that referenced this issue Feb 5, 2015
* contributes to #29
* pushed to Scala.js 0.6.0 + utest 0.3.0
* contributes to #27
@jokade jokade closed this as completed in caea181 Feb 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant