fix(ngRepeat): correct variable reference in error message

Closese #803
This commit is contained in:
Igor Minar 2012-03-17 15:57:55 -07:00
parent 78a6291666
commit 935c1018da
2 changed files with 11 additions and 4 deletions

View file

@ -73,10 +73,10 @@ var ngRepeatDirective = ngDirective({
}
lhs = match[1];
rhs = match[2];
match = lhs.match(/^([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\)$/);
match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);
if (!match) {
throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '" +
keyValue + "'.");
lhs + "'.");
}
valueIdent = match[3] || match[1];
keyIdent = match[2];

View file

@ -64,12 +64,19 @@ describe('ng-repeat', function() {
}));
it('should error on wrong parsing of ng-repeat', inject(function($rootScope, $compile, $log) {
it('should error on wrong parsing of ng-repeat', inject(function($rootScope, $compile) {
expect(function() {
element = $compile('<ul><li ng-repeat="i dont parse"></li></ul>')($rootScope);
}).toThrow("Expected ng-repeat in form of '_item_ in _collection_' but got 'i dont parse'.");
}));
$log.error.logs.shift();
it("should throw error when left-hand-side of ng-repeat can't be parsed", inject(
function($rootScope, $compile) {
expect(function() {
element = $compile('<ul><li ng-repeat="i dont parse in foo"></li></ul>')($rootScope);
}).toThrow("'item' in 'item in collection' should be identifier or (key, value) but got " +
"'i dont parse'.");
}));