I'm accessing a scope like so:
let element = angular.element(document.getElementsByClassName('active'));
let scope = element.scope();
And my scope object looks like this when I do a
console.log(scope);
$id:2017 $parent:ChildScope $root:Scope __private__:Object index:0 match:Object __proto__:Object
However when I try to do:
console.log(scope.match);
Typescript gives a syntax error:
(27,34): error TS2339: Property 'match' does not exist on type 'IScope'.
And printing out scope.$id works
console.log(scope.$id);
I know it has something to do $id being defined in the docs so that works. http://definitelytyped.org/docs/angularjs--angular-route/interfaces/ng.iscope.html
How would I print out my member variable scope.match
without getting a Typescript error? I think I would need to extend ng.IScope?
I was able to fix the problem by exporting an interface and then casting ng.IScope.
Make sure to use ? to make it an optional parameter. That's where I went wrong
export interface IMyScope extends ng.IScope {
match?: any;
}
And then:
let myScope = <IMyScope>element.scope();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With