fix(change_detection): convert interpolated null values to empty strings
Fixes #3007 Closes #3271
This commit is contained in:
parent
16493e9769
commit
345fa521dd
@ -371,7 +371,7 @@ export class ChangeDetectorJITGenerator {
|
|||||||
for (var i = 0; i < r.args.length; ++i) {
|
for (var i = 0; i < r.args.length; ++i) {
|
||||||
res += JSON.stringify(r.fixedArgs[i]);
|
res += JSON.stringify(r.fixedArgs[i]);
|
||||||
res += " + ";
|
res += " + ";
|
||||||
res += this._localNames[r.args[i]];
|
res += `${UTIL}.s(${this._localNames[r.args[i]]})`;
|
||||||
res += " + ";
|
res += " + ";
|
||||||
}
|
}
|
||||||
res += JSON.stringify(r.fixedArgs[r.args.length]);
|
res += JSON.stringify(r.fixedArgs[r.args.length]);
|
||||||
|
@ -151,4 +151,6 @@ export class ChangeDetectionUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static isValueBlank(value: any): boolean { return isBlank(value); }
|
static isValueBlank(value: any): boolean { return isBlank(value); }
|
||||||
|
|
||||||
|
static s(value: any): string { return isPresent(value) ? `${value}` : ''; }
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,15 @@ export function main() {
|
|||||||
expect(val.dispatcher.log).toEqual(['propName=BvalueA']);
|
expect(val.dispatcher.log).toEqual(['propName=BvalueA']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should output empty strings for null values in interpolation', () => {
|
||||||
|
var val = _createChangeDetector('interpolation', new TestData('value'));
|
||||||
|
val.changeDetector.hydrate(new TestData(null), null, null, null);
|
||||||
|
|
||||||
|
val.changeDetector.detectChanges();
|
||||||
|
|
||||||
|
expect(val.dispatcher.log).toEqual(['propName=BA']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should escape values in literals that indicate interpolation',
|
it('should escape values in literals that indicate interpolation',
|
||||||
() => { expect(_bindSimpleValue('"$"')).toEqual(['propName=$']); });
|
() => { expect(_bindSimpleValue('"$"')).toEqual(['propName=$']); });
|
||||||
|
|
||||||
|
@ -94,6 +94,19 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should update text node with a blank string when interpolation evaluates to null',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
tcb.overrideView(MyComp, new viewAnn.View({template: '<div>{{null}}{{ctxProp}}</div>'}))
|
||||||
|
.createAsync(MyComp)
|
||||||
|
.then((rootTC) => {
|
||||||
|
rootTC.componentInstance.ctxProp = null;
|
||||||
|
|
||||||
|
rootTC.detectChanges();
|
||||||
|
expect(rootTC.nativeElement).toHaveText('');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should consume element binding changes',
|
it('should consume element binding changes',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
tcb.overrideView(MyComp, new viewAnn.View({template: '<div [id]="ctxProp"></div>'}))
|
tcb.overrideView(MyComp, new viewAnn.View({template: '<div [id]="ctxProp"></div>'}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user