This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Whitespace in let x1 = index
causes silent failures.
#880
Comments
Thanks! I'll take a look. |
|
Hi @matanlurey - I've created a bare bones project here showing the issue: |
@jimmyff I'm getting a pass with a similar setup: @TestOn('browser')
import 'dart:html';
import 'package:angular/angular.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';
import '880_ng_for_input_test.template.dart' as ng_generated;
void main() {
tearDown(disposeAnyRunningTest);
test('should support directive inputs from an ngFor index', () async {
final testBed = NgTestBed.forComponent<UsesNgFor>(
ng_generated.UsesNgForNgFactory,
);
final fixture = await testBed.create();
expect(fixture.text, '(0, 0)(1, 0)(0, 1)(1, 1)');
});
}
@Component(
selector: 'uses-ng-for',
directives: const [
GridCell,
NgFor,
],
template: r'''
<div *ngFor="let row of getRows(); let y1 = index">
<div *ngFor="let col of getCols(y1); let x1 = index">
<div gridCell [x]="x1" [y]="y1"></div>
</div>
</div>
''',
)
class UsesNgFor {
List<String> getRows() => const ['a', 'b'];
List<String> getCols(int index) => const ['1', '2'];
}
@Directive(
selector: '[gridCell]',
)
class GridCell implements AfterChanges {
final Element _element;
GridCell(this._element);
@Input()
int x;
@Input()
int y;
@override
void ngAfterChanges() {
_element.text = '($x, $y)';
}
} |
Do you see anything silly different? |
omg -it's the whitespace after the word index!! Fails: <div *ngFor="let row of getRows(); let y1 = index ">
<div *ngFor="let col of getCols(y1); let x1 = index ">
<div [x]="x1" [y]="y1" gridCell></div>
</div>
</div> Passes: <div *ngFor="let row of getRows(); let y1 = index">
<div *ngFor="let col of getCols(y1); let x1 = index">
<div [x]="x1" [y]="y1" gridCell></div>
</div>
</div> That is a horrible gotcha! |
matanlurey
added
area: compiler
☄ problem: bug
⛈ experience: dev cycle
area: ast
and removed
✍️ needs review
labels
Feb 13, 2018
matanlurey
changed the title
Directive input not working when provided with *ngFor index
Whitespace in Feb 13, 2018
let x1 = index
causes silent failures.
I think we can handle this with a simple |
Fixed in #1565! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm using alpha5 + DDC. This directive worked fine with Angular4 + pub.
The directive with selector
[gridCell]
@Input()
never gets called/set when provided with index values from*ngFor
. If I hardcode numbers instead of providingx1
&y1
then the@Input()
gets successfully called/set.Component template:
The directive is definitely loaded, I have it printing a message on construct. I also have simplified it so it's a barebones directive, it literally just prints debug on construct and when x or y is set.
The text was updated successfully, but these errors were encountered: