I created the angular directive as follows:
angular.module('SharedModule')
.directive('multiSelect', ['$ionicModal', multiSelect]);
function multiSelect($ionicModal) {
return {
restrict: 'E',
template: [
'<div ng-click="showItems($event)" class="item-icon-right item">',
'{{text}}',
'<i class="icon ion-ios-arrow-right"></i>',
'</div>'
].join(""),
scope: {
'items': '=',
'value': '=ngModel'
},
link: function (scope, element, attrs, $filter) {
scope.validate = function () {
};
scope.$on('$destroy', function () {
scope.modal.remove();
});
}
}
}
Basically, this gives the user the ability to select several types of contacts from the modal dialog used in the ionic application.
I use this directive in my html (inside the form) as follows:
<multi-select
name="contactTypes"
items="contact_types"
text="Contact types"
header-text="Choose contact types"
allow-empty="false"
ng-model="contact.contact_types"
></multi-select>
Question: I'm not sure how to install ng-pristine, ng-needed ng-pristine classes if the user hasn't selected anything. Where will the code for managing custom validation work? What do I need to do so that I can use this directive like any other input control with an ng model?
source
share