fix(compiler): don't inject viewProviders into content child elements

E.g. in the following scenario,
`some-directive` should not be able to inject
any view provider that `my-comp-with-view-providers`
declares.

```
<my-comp-with-view-providers>
  <div some-directive></div>
</my-comp-with-view-providers>
```
This commit is contained in:
Tobias Bosch
2016-06-23 09:59:45 -07:00
parent 33a2f86b28
commit 9ed8f2d26e
2 changed files with 19 additions and 1 deletions

View File

@ -313,6 +313,14 @@ export class CompileElement extends CompileNode {
}
// access regular providers on the element
if (isBlank(result)) {
let resolvedProvider = this._resolvedProviders.get(dep.token);
// don't allow directives / public services to access private services.
// only components and private services can access private services.
if (resolvedProvider && (requestingProviderType === ProviderAstType.Directive ||
requestingProviderType === ProviderAstType.PublicService) &&
resolvedProvider.providerType === ProviderAstType.PrivateService) {
return null;
}
result = this._instances.get(dep.token);
}
}