Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit c1209a4

Browse files
committed
fix(defaultValue): fix nested keys to work with default values
defaultValue now uses $parse to set keys refs #468
1 parent 1a2175b commit c1209a4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/directives/formly-field.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
110110

111111
function setDefaultValue() {
112112
if (angular.isDefined($scope.options.defaultValue) && !angular.isDefined($scope.model[$scope.options.key])) {
113-
$scope.model[$scope.options.key] = $scope.options.defaultValue;
113+
const setter = $parse($scope.options.key).assign;
114+
setter($scope.model, $scope.options.defaultValue);
114115
}
115116
}
116117

src/directives/formly-field.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ describe('formly-field', function() {
511511
scope.fields.push(secondField);
512512
});
513513

514-
it.skip(`should set the default value for nested keys`, () => {
514+
it(`should set the default value for nested keys`, () => {
515515
compileAndDigest();
516516
expect(scope.model.foo.bar).to.equal(defaultValue);
517517
expect(scope.model.baz[0]).to.equal(defaultValue);

0 commit comments

Comments
 (0)