fix(compiler): fix cross view references and providers with useValue.

Before, we would create all fields in the generated views
with visibility `private`. This does not work if an embedded
view references a directive / element in a parent view.
In Dart, this was no problem so far as it does not have
a `private` modifier.

Before, `useValue` in a provider did not work when doing
offline compile, as so far the `MetadataResolver` was only
used for jit mode. Now, `useValue` supports any kind of value
that the static reflector can return. E.g. primitives,
arrays, string maps, …

Closes #8366
This commit is contained in:
Tobias Bosch
2016-04-30 16:13:03 -07:00
parent 163d80adb7
commit f114d6c560
17 changed files with 176 additions and 34 deletions

View File

@ -1,14 +1,9 @@
import {Component, Injectable} from 'angular2/core';
import {Component, Inject} from 'angular2/core';
import {FORM_DIRECTIVES} from 'angular2/common';
import {MyComp} from './a/multiple_components';
@Component({
selector: 'basic',
templateUrl: './basic.html',
directives: [MyComp, FORM_DIRECTIVES],
})
@Injectable()
@Component({selector: 'basic', templateUrl: './basic.html', directives: [MyComp, FORM_DIRECTIVES]})
export class Basic {
ctxProp: string;
constructor() { this.ctxProp = 'initial value'; }
constructor() { this.ctxProp = 'initiaValue'; }
}

View File

@ -0,0 +1,29 @@
import {Component, Inject, OpaqueToken} from 'angular2/core';
import {NgIf} from 'angular2/common';
export const SOME_OPAQUE_TOKEN = new OpaqueToken('opaqueToken');
@Component({
selector: 'comp-providers',
template: '',
providers: [
{provide: 'strToken', useValue: 'strValue'},
{provide: SOME_OPAQUE_TOKEN, useValue: 10},
{provide: 'reference', useValue: NgIf},
{provide: 'complexToken', useValue: {a: 1, b: ['test', SOME_OPAQUE_TOKEN]}},
]
})
export class CompWithProviders {
constructor(@Inject('strToken') public ctxProp) {}
}
@Component({
selector: 'cmp-reference',
template: `
<input #a>{{a.value}}
<div *ngIf="true">{{a.value}}</div>
`,
directives: [NgIf]
})
export class CompWithReferences {
}