Skip to content

Commit 56220b4

Browse files
committed
Angular 1.2 fix for arrays
A broken watch since it lacked a '.' in 1.2 when object path doesn't use brackets.
1 parent f8084d5 commit 56220b4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/directives/array.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
3333
// It's the (first) array part of the key, '[]' that needs a number
3434
// corresponding to an index of the form.
3535
var once = scope.$watch(attrs.sfArray, function(form) {
36+
if (!form) {
37+
return;
38+
}
39+
3640

3741
// An array model always needs a key so we know what part of the model
3842
// to look at. This makes us a bit incompatible with JSON Form, on the
@@ -42,7 +46,8 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
4246
// We only modify the same array instance but someone might change the array from
4347
// the outside so let's watch for that. We use an ordinary watch since the only case
4448
// we're really interested in is if its a new instance.
45-
scope.$watch('model' + sfPath.normalize(form.key), function(value) {
49+
var key = sfPath.normalize(form.key);
50+
scope.$watch('model' + (key[0] !== '[' ? '.' : '') + key, function(value) {
4651
list = scope.modelArray = value;
4752
});
4853

0 commit comments

Comments
 (0)