Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

example in docs for $controller appears wrong #12550

Closed
lsiden opened this issue Aug 11, 2015 · 3 comments
Closed

example in docs for $controller appears wrong #12550

lsiden opened this issue Aug 11, 2015 · 3 comments

Comments

@lsiden
Copy link

lsiden commented Aug 11, 2015

The docs for ngMock.$controller
give an example of it's invocation as

myMod.directive('myDirective', {
  controller: 'MyDirectiveController',
  bindToController: {
    name: '@'
  }
});
// Controller definition ...
myMod.controller('MyDirectiveController', ['log', function($log) {
  $log.info(this.name);
})];

Then,

$controller('MyDirective', { /* no locals */ }, { name: 'Clark Kent' })

But 'MyDirective' is the registered name of the directive, not the controller. Nowhere in the docs for $controller does it say that $controller will look up a controller by the name of a directive that binds to it. Is this a mistake in the docs?

@caitp
Copy link
Contributor

caitp commented Aug 11, 2015

The example is showing you how to test "bind-to-controller" stuff, without having to rely on the $compile service. This was asked for. So, if you scroll down a bit further, the entire example shows you how you can completely set up mock bindings.

The top portion of the example is referring to your application code, whereas further down, it's a simple test case which only needs to use the $controller service to get the job done.

@caitp
Copy link
Contributor

caitp commented Aug 11, 2015

although, you may be right, I can't recall if that was a typo or not, need to inspect the patch. If it is a typo, a fix is welcome

@caitp
Copy link
Contributor

caitp commented Aug 11, 2015

Yes, please send a patch to change it to $controller('MyDirectiveController', thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants