AngularJS date in ng-model value not pass to controller

前端 未结 2 799
小鲜肉
小鲜肉 2021-01-23 09:55

when i click CheckAvailability button date value doesnot pass to controller

2条回答
  •  無奈伤痛
    2021-01-23 10:32

    Forget ASP. In AngularJS input doesn't need a value. Simply populate the ng-model. You can do it in controller or with ng-init in HTML. To mask/filter the date, use $filter service. It's usually not used directly, so I suggest applying a filter in ng-init. AngularJS has a date filter for this purpose.

    Here is an example:

    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
      $scope.now = new Date();
      $scope.CheckAvailability = function() {
        console.log("Date:", $scope.BookedFromDate);
      };
    });
    
    
    
    
    
      


    Alternatively change the type from text to date to completely ignore the filter and masking.

    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
      $scope.BookedFromDate = new Date();
      $scope.CheckAvailability = function() {
        console.log("Date:", $scope.BookedFromDate);
      };
    });
    
    
    
    
    
      

提交回复
热议问题