angularjs - Angular (directive newbie): How to add date time-picker to ngModel so that it can be validated? -


i new angular , have specific use case in mind have form has 2 fields - name , datetime.

the name ng-model datetime not since not part of angular , jquery component

what want do?
here plunker = http://plnkr.co/edit/wgrvxafmpgoyswh9gfxh?p=preview

a.) want associate date ngmodel ngmodel="transaction.date"
b.) validate required using angular way

something (much angular)

<input type="text" name="transactiondate" ng-model="transaction.date" data-date-format="yyyy-mm-dd hh:ii" required> 

why?
a.) to things angular way
b.) makes model more consistent test, validate

i asked question on stackoverflow , recommended use custom directive, can give me direction example how it?

please guide me further since not able validate currently

thank much

based on ketan's answer, had write new directive , associate value form jquery ng-model, validated form. directive looks like

app.directive('datetime', function(){   return {     restrict: 'a',     require: '?ngmodel',     link: function(scope, element, attrs, ngmodel){       if (!ngmodel) {         console.log('no model, returning');         return;       }        element.bind('blur keyup change', function() {         console.log('datetime changed: ', $('.form_datetime input').val());         scope.$apply(read);       });        read();        function read() {         ngmodel.$setviewvalue(element.val());       }     }   } }); 

the plunker can found here


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -