fix(NgRepeat): activate index

This commit is contained in:
Marc Laval 2015-01-28 00:42:08 +01:00 committed by Rado Kirov
parent db0f0c462b
commit 52d88457c8
4 changed files with 7 additions and 10 deletions

View File

@ -71,8 +71,7 @@ export class View {
setLocal(contextName: string, value) {
if (!this.hydrated()) throw new BaseException('Cannot set locals on dehydrated view.');
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
throw new BaseException(
`Local binding ${contextName} not defined in the view template.`);
return;
}
var templateName = MapWrapper.get(this.proto.variableBindings, contextName);
this.context.set(templateName, value);

View File

@ -84,8 +84,8 @@ export function main() {
expect(view.context.get('template-foo')).toBe('bar');
});
it('should throw on undeclared locals', () => {
expect(() => view.setLocal('setMePlease', 'bar')).toThrowError();
it('should not throw on undeclared locals', () => {
expect(() => view.setLocal('setMePlease', 'bar')).not.toThrow();
});
it('when dehydrated should set locals to null', () => {

View File

@ -50,8 +50,7 @@ export class NgRepeat extends OnChange {
perViewChange(view, record) {
view.setLocal('ng-repeat', record.item);
// Uncomment when binding is ready.
// view.setLocal('index', record.item);
view.setLocal('index', record.currentIndex);
}
static bulkRemove(tuples, viewPort) {

View File

@ -191,10 +191,9 @@ export function main() {
});
});
/*
TODO(rado): enable after compiler is fixed.
it('should display indices correctly', (done) => {
var INDEX_TEMPLATE = '<div><copy-me template="ng-repeat #item in items index #i">{{index.toString()}};</copy-me></div>';
var INDEX_TEMPLATE = '<div><copy-me template="ng-repeat #item in items index #i">{{i.toString()}}</copy-me></div>';
compileWithTemplate(INDEX_TEMPLATE).then((pv) => {
createView(pv);
component.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@ -207,7 +206,7 @@ TODO(rado): enable after compiler is fixed.
done();
});
});
*/
});
}