angularjs - name array with ng-model
I'm learning angularjs so please bare with me.
I have an add button that uses a directive to add-to a table's
(.estimates) tbody:
function EstimateCtrl( $scope, $compile ) {
$scope.add = function() {
angular.element('.estimates tbody').append( $compile('<tr
estimate></tr>')($scope) );
}
}
angular.module('dashboard', [])
.directive('estimate', function() {
return {
restrict: 'A',
template: '<td><input type="text"
placeholder="Suburb"/></td><td><select
ng-model="estimate.service" ng-options="service.value as
service.name for service in services"
class="form-control"></select></td><td>$0.00</td><td><button
type="button" class="remove">x</button></td>',
link: function( scope, element, attrs ) {
element.find('.remove').bind('click', function() {
element.closest('tr').remove();
});
}
}
});
How can I have an element array using ng-model in angularjs? For example:
<select name="foo[]"></select>
to
<select ng-model="foo[]"></select>
I've been digging around for a day and half but I can't seem to catch a
break. I was hoping that maybe someone can point me in the right
direction. Thank you very much for any help.
No comments:
Post a Comment