George Mauer George Mauer - 1 year ago 68
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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download