X Tutup
Skip to content

Commit 52d8845

Browse files
marclavalrkirov
authored andcommitted
fix(NgRepeat): activate index
1 parent db0f0c4 commit 52d8845

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

modules/core/src/compiler/view.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export class View {
7171
setLocal(contextName: string, value) {
7272
if (!this.hydrated()) throw new BaseException('Cannot set locals on dehydrated view.');
7373
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
74-
throw new BaseException(
75-
`Local binding ${contextName} not defined in the view template.`);
74+
return;
7675
}
7776
var templateName = MapWrapper.get(this.proto.variableBindings, contextName);
7877
this.context.set(templateName, value);

modules/core/test/compiler/view_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export function main() {
8484
expect(view.context.get('template-foo')).toBe('bar');
8585
});
8686

87-
it('should throw on undeclared locals', () => {
88-
expect(() => view.setLocal('setMePlease', 'bar')).toThrowError();
87+
it('should not throw on undeclared locals', () => {
88+
expect(() => view.setLocal('setMePlease', 'bar')).not.toThrow();
8989
});
9090

9191
it('when dehydrated should set locals to null', () => {

modules/directives/src/ng_repeat.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export class NgRepeat extends OnChange {
5050

5151
perViewChange(view, record) {
5252
view.setLocal('ng-repeat', record.item);
53-
// Uncomment when binding is ready.
54-
// view.setLocal('index', record.item);
53+
view.setLocal('index', record.currentIndex);
5554
}
5655

5756
static bulkRemove(tuples, viewPort) {

modules/directives/test/ng_repeat_spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,9 @@ export function main() {
191191
});
192192
});
193193

194-
/*
195-
TODO(rado): enable after compiler is fixed.
194+
196195
it('should display indices correctly', (done) => {
197-
var INDEX_TEMPLATE = '<div><copy-me template="ng-repeat #item in items index #i">{{index.toString()}};</copy-me></div>';
196+
var INDEX_TEMPLATE = '<div><copy-me template="ng-repeat #item in items index #i">{{i.toString()}}</copy-me></div>';
198197
compileWithTemplate(INDEX_TEMPLATE).then((pv) => {
199198
createView(pv);
200199
component.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@@ -207,7 +206,7 @@ TODO(rado): enable after compiler is fixed.
207206
done();
208207
});
209208
});
210-
*/
209+
211210
});
212211
}
213212

0 commit comments

Comments
 (0)
X Tutup