Skip to content

Commit

Permalink
fixup: fix(core): WIP - support Attribute DI decorator in deps se…
Browse files Browse the repository at this point in the history
…ction of a token
  • Loading branch information
sonukapoor committed May 13, 2020
1 parent 7e37bd8 commit 279261b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
9 changes: 5 additions & 4 deletions packages/core/src/di/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {makeParamDecorator} from '../util/decorators';
import {ɵɵinjectAttribute} from '../render3/instructions/di';
import {makeParamDecorator} from '../util/decorators';


/**
Expand Down Expand Up @@ -283,6 +283,7 @@ export interface Attribute {
* @Annotation
* @publicApi
*/
export const Attribute: AttributeDecorator =
makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName,
__NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
export const Attribute: AttributeDecorator = makeParamDecorator(
'Attribute',
(attributeName?: string) =>
({attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
30 changes: 1 addition & 29 deletions packages/core/test/acceptance/di_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ describe('di', () => {
});
});

fdescribe('attribute tokens', () => {
describe('attribute tokens', () => {
it('should be able to provide an attribute token', () => {
const TOKEN = new InjectionToken<string>('Some token');
function factory(token: string): string {
Expand Down Expand Up @@ -1830,34 +1830,6 @@ describe('di', () => {
fixture.detectChanges();
expect(fixture.componentInstance.myComp.token).toBe('token with factory');
});

it('should be able to provide an attribute token through the ngModule decorator', () => {
@Injectable({
providedIn: 'root',
useFactory: (token: string) => new Service(token),
deps: [new Attribute('token')]
})
class Service {
constructor(public token: string) {}
}

@Component({
selector: 'my-comp',
template: '...',
providers: [{provide: 'token', useValue: 'component token'}]
})
class MyComp {
constructor(public service: Service) {}
}

TestBed.configureTestingModule(
{declarations: [MyComp], providers: [{provide: 'token', useValue: 'module token'}]});

const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();

expect(fixture.componentInstance.service.token).toBe('module token');
});
});

it('should not cause cyclic dependency if same token is requested in deps with @SkipSelf', () => {
Expand Down

0 comments on commit 279261b

Please sign in to comment.