Not getting value of input type created through a directive in angularJS -


i using directive datepicker in angularjs. below code directive. works , shows datepicker when add datepicker directive in div.now want use selected date in form when send data in controller , controller pass php api via $http. when check data in php not shows date. rest fields working fine field created directive not showing values. pasting code directive, controller , form.

app.directive('datepicker', function () {     return {         restrict: 'a',         controller: 'datepickerctrl',         controlleras: 'dp',         template: '<div id="dob" ng-controller="profilectrl" dob class="input-group date" data-date-format="dd-mm-yyyy" ><input class="from_to_input"  name="1" type="text" ng-class={inputerror:dp.validdate==false} class="form-control input-sm"  ng-model="profile.value"/><span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span></div>',         scope: {             'value': '='         },         link: function (scope, element, attribute) {             //  scope.variable = attribute.value;         }     }; }); 

below code controller datepicker

  app.controller('datepickerctrl', function ($scope) {             $('.date').datepicker({ autoclose: true, todayhighlight: true });     var inputdate = new date(moment($scope.value));     $scope.value = moment(inputdate).format("dd-mm-yyyy");     $('.date').datepicker('setdate', inputdate);      $scope.$watch('value', function (newval) {                       }); }); 

below code form page

<form name="profileform" role="form">                     <input type="email" id="" name="email"  ng-model="profile.email" class="login_input_area" placeholder="email">                      <div class="col-xs-2" datepicker  value="date2"></div>                     <input type="submit" value="submit" ng-click="saveprofile(profile)" class="submit_btn">                 </form> 

my friend! please check online video tutorials angular directives!

anyway, in directive have ng-model="profile.value", should "value" think

second: remove ng-controller="profilectrl" directive template. directives has own local scope.

third: prefer using restrict: "e", can use custom tag, more readable on opinion

one more: scope: { value : "="} , not scope: { 'value' : "="}

couple more: remove both controller: 'datepickerctrl', controlleras: 'dp'


Comments