0
<input type="text" ng-model="expiry.year" />
<input type="text" ng-model="expiry.month" />
<input type="text" ng-model="expiry.date" />

{
expiration: expiry.year + expiry.month, expiry.date
}

How to concatenate this into one model?I have this inout fields exist in a multiple form.

2
  • I have to check friend... Commented Aug 25, 2014 at 5:20
  • Plese setup a plunker. You could use ng-change to update expiration when expiry is changed or do a watch. Commented Aug 25, 2014 at 5:30

2 Answers 2

1

not a complete solution but you can work along these lines

<input type="text" ng-model="expiry.year" ng-change="expiration = expiry.year + expiry.month, expiry.date" />
<input type="text" ng-model="expiry.month" ng-change="expiration = expiry.year + expiry.month, expiry.date"  />
<input type="text" ng-model="expiry.date" ng-change="expiration = expiry.year + expiry.month, expiry.date"  />

it does not handle undefined etc case. better would be to write a function and do the concatenation in controller...

<input type="text" ng-model="expiry.year" ng-change="expirationUpdated()" />
<input type="text" ng-model="expiry.month" ng-change="expirationUpdated()" />
<input type="text" ng-model="expiry.date" ng-change="expirationUpdated()" />

do it in function

var expirationUpdated = function() { ///concate logic here}
Sign up to request clarification or add additional context in comments.

1 Comment

Good idea on this part "ng-change" and call the function.I'll let the server handle my problem so that on edit/update no concatenation thing.makes code cleaner.@HarishR
1
<input type="text" ng-model="expiry.year" />
<input type="text" ng-model="expiry.month" />
<input type="text" ng-model="expiry.date" />

{{ expiration }}

You can setup a watch in your controller

$scope.$watch('expiry', function(newVal) {
    $scope.expiration = newVal.year + '-' + newVal.month + '-' + newVal.date
}, true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.