1

I need one help. I am implementing jquery.timepicker.js to get the time interval in my Angular application but i am not getting any value like that.I am explaining my code below.

<div class="input-group bmargindiv1 col-md-12">
      <span class="input-group-addon ndrftextwidth text-right" style="width:180px">From Time :</span>
      <input type="text" name="time" id="time" class="form-control oditek-form" placeholder="E.G-9.00AM" ng-model="time" ng-change="clearField('time');" maxlength="30" time-picker="" />
    </div>
    <div class="input-group bmargindiv1 col-md-12">
      <span class="input-group-addon ndrftextwidth text-right" style="width:180px">To Time :</span>
      <input type="text" name="time1" id="time1" class="form-control oditek-form" placeholder="E.G-9.00AM" ng-model="time1" ng-change="clearField('time1');" maxlength="30" time-picker="" />
    </div>
  </div>
  <div style="text-align:center; padding:10px 0px;">
    <input type="button" class="btn btn-success" ng-click="addTimeDetails();" id="saveData" value="Add" style="margin-right:20px;" />
  </div>

my controller side code is given below.

var app=angular.module('spesh',[]);
app.controller('formController',function($scope,$http){
  $scope.addTimeDetails=function(){
    console.log('time',$scope.time,$scope.time1);
  }
})
app.directive('timePicker', [function () {
        return {
        restrict: 'A',
        require: 'ngModel',
        scope: {
            model: '=ngModel'
        },
        link: function ($scope, element, attrs, ngModelCtrl) {
            element.timepicker();
            element.on('changeTime', function () {
              $scope.$apply(function () {
                $scope.model = element.val();
              });
            });

        }
    }
}]);

Here i need when user will click on text field the time drop down will come and click on add button the selected time will show in console.MY complete code is here in plunkr.Please help me.

1 Answer 1

1

Change <html ng-model="spesh"> to <html ng-app="spesh">

Here is better solution: https://plnkr.co/edit/A0sSqXzx73XYn0f7UVGD?p=preview

When you require ngModel, you can use it's methods or read value. You don't need to read ngModel attribute.

$setViewValue(value, trigger); Update the view value.

This method should be called when a control wants to change the view value; typically, this is done from within a DOM event handler. For example, the input directive calls it when the value of the input changes and select calls it when an option is selected.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, mark it as answer than or delete a question. :)

Your Answer

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