user3310447
user3310447

Reputation: 135

Karma get scope of Angular directive

I am using karma to load an angular directive (with the html2js plugin):

beforeEach(module('partials/myDir.html'));

beforeEach(inject(function($injector, $compile, $rootScope){
    $gCompile = $compile;
             $gScope = $rootScope;

}));

it("test test", function() {
    element = $gCompile('<my-dir></my-dir>')($gScope);
    $gScope.$digest();
    console.log($gScope);
});

This all works fine, what I now want to do is access the directives scope from the $rootScope object injected in the beforeEach.

Upvotes: 0

Views: 1054

Answers (1)

joshkurz
joshkurz

Reputation: 1033

It depends upon your directive definition object. I don't see one in your question so I will answer for all three options.

Defining Scope or Child Scope: This would be set by either doing scope: true or using the default scope value, which is false.

 element.scope()

Isolate Scope:

This would be used if an Isolate Scope is created by your directive.

 element.IsolateScope() 

Upvotes: 4

Related Questions