parent
dc300c5c41
commit
3c9ad1d231
|
@ -262,7 +262,7 @@ export function diPublicInInjector(
|
||||||
*
|
*
|
||||||
* @publicApi
|
* @publicApi
|
||||||
*/
|
*/
|
||||||
export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): string|undefined {
|
export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): string|null {
|
||||||
ngDevMode && assertNodeOfPossibleTypes(
|
ngDevMode && assertNodeOfPossibleTypes(
|
||||||
tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
|
tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
|
||||||
ngDevMode && assertDefined(tNode, 'expecting tNode');
|
ngDevMode && assertDefined(tNode, 'expecting tNode');
|
||||||
|
@ -276,7 +276,7 @@ export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2758,7 +2758,7 @@ export function directiveInject<T>(
|
||||||
/**
|
/**
|
||||||
* Facade for the attribute injection from DI.
|
* Facade for the attribute injection from DI.
|
||||||
*/
|
*/
|
||||||
export function injectAttribute(attrNameToInject: string): string|undefined {
|
export function injectAttribute(attrNameToInject: string): string|null {
|
||||||
return injectAttributeImpl(getPreviousOrParentTNode(), attrNameToInject);
|
return injectAttributeImpl(getPreviousOrParentTNode(), attrNameToInject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1268,7 +1268,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy('unknown') && it('should support static attributes', () => {
|
it('should support static attributes', () => {
|
||||||
TestBed.configureTestingModule({declarations: [MyComp, NeedsAttribute]});
|
TestBed.configureTestingModule({declarations: [MyComp, NeedsAttribute]});
|
||||||
const template = '<input static type="text" title>';
|
const template = '<input static type="text" title>';
|
||||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||||
|
|
|
@ -1751,11 +1751,11 @@ describe('di', () => {
|
||||||
let myDirectiveInstance !: MyDirective | null;
|
let myDirectiveInstance !: MyDirective | null;
|
||||||
|
|
||||||
class MyDirective {
|
class MyDirective {
|
||||||
exists = 'wrong' as string | undefined;
|
exists = 'wrong' as string | null;
|
||||||
myDirective = 'wrong' as string | undefined;
|
myDirective = 'wrong' as string | null;
|
||||||
constructor(
|
constructor(
|
||||||
@Attribute('exist') existAttrValue: string|undefined,
|
@Attribute('exist') existAttrValue: string|null,
|
||||||
@Attribute('myDirective') myDirectiveAttrValue: string|undefined) {
|
@Attribute('myDirective') myDirectiveAttrValue: string|null) {
|
||||||
this.exists = existAttrValue;
|
this.exists = existAttrValue;
|
||||||
this.myDirective = myDirectiveAttrValue;
|
this.myDirective = myDirectiveAttrValue;
|
||||||
}
|
}
|
||||||
|
@ -1771,8 +1771,8 @@ describe('di', () => {
|
||||||
beforeEach(() => myDirectiveInstance = null);
|
beforeEach(() => myDirectiveInstance = null);
|
||||||
|
|
||||||
it('should inject attribute', () => {
|
it('should inject attribute', () => {
|
||||||
let exist = 'wrong' as string | undefined;
|
let exist = 'wrong' as string | null;
|
||||||
let nonExist = 'wrong' as string | undefined;
|
let nonExist = 'wrong' as string | null;
|
||||||
|
|
||||||
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
||||||
if (rf & RenderFlags.Create) {
|
if (rf & RenderFlags.Create) {
|
||||||
|
@ -1784,7 +1784,7 @@ describe('di', () => {
|
||||||
|
|
||||||
new ComponentFixture(MyApp);
|
new ComponentFixture(MyApp);
|
||||||
expect(exist).toEqual('existValue');
|
expect(exist).toEqual('existValue');
|
||||||
expect(nonExist).toEqual(undefined);
|
expect(nonExist).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://stackblitz.com/edit/angular-scawyi?file=src%2Fapp%2Fapp.component.ts
|
// https://stackblitz.com/edit/angular-scawyi?file=src%2Fapp%2Fapp.component.ts
|
||||||
|
@ -1831,8 +1831,8 @@ describe('di', () => {
|
||||||
|
|
||||||
// https://stackblitz.com/edit/angular-8ytqkp?file=src%2Fapp%2Fapp.component.ts
|
// https://stackblitz.com/edit/angular-8ytqkp?file=src%2Fapp%2Fapp.component.ts
|
||||||
it('should not inject attributes representing bindings and outputs', () => {
|
it('should not inject attributes representing bindings and outputs', () => {
|
||||||
let exist = 'wrong' as string | undefined;
|
let exist = 'wrong' as string | null;
|
||||||
let nonExist = 'wrong' as string | undefined;
|
let nonExist = 'wrong' as string | null;
|
||||||
|
|
||||||
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
||||||
if (rf & RenderFlags.Create) {
|
if (rf & RenderFlags.Create) {
|
||||||
|
@ -1844,12 +1844,12 @@ describe('di', () => {
|
||||||
|
|
||||||
new ComponentFixture(MyApp);
|
new ComponentFixture(MyApp);
|
||||||
expect(exist).toEqual('existValue');
|
expect(exist).toEqual('existValue');
|
||||||
expect(nonExist).toEqual(undefined);
|
expect(nonExist).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not accidentally inject attributes representing bindings and outputs', () => {
|
it('should not accidentally inject attributes representing bindings and outputs', () => {
|
||||||
let exist = 'wrong' as string | undefined;
|
let exist = 'wrong' as string | null;
|
||||||
let nonExist = 'wrong' as string | undefined;
|
let nonExist = 'wrong' as string | null;
|
||||||
|
|
||||||
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
const MyApp = createComponent('my-app', function(rf: RenderFlags, ctx: any) {
|
||||||
if (rf & RenderFlags.Create) {
|
if (rf & RenderFlags.Create) {
|
||||||
|
@ -1863,7 +1863,7 @@ describe('di', () => {
|
||||||
|
|
||||||
new ComponentFixture(MyApp);
|
new ComponentFixture(MyApp);
|
||||||
expect(exist).toEqual('existValue');
|
expect(exist).toEqual('existValue');
|
||||||
expect(nonExist).toEqual(undefined);
|
expect(nonExist).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue