George Mauer George Mauer - 10 months ago 49
AngularJS Question

How to access component controller when testing?

I am trying to put together some tests of a component. I have the following

describe(`selecting an item`, () => {
let element, $scope;

beforeEach(inject(($compile, $rootScope) => {
$scope = $rootScope;
element = $compile(`
<item-selector parent-id="pid">

//call $ctrl.activate() on the component's controller


the controller for
has an
method. How can I invoke it from my test?
doesn't seem to contain any reference.

Answer Source
let ctrl = element.controller('item-selector')