【问题标题】:angular (jquery timepicker) unable to get value of input角度(jquery timepicker)无法获取输入值
【发布时间】:2015-08-25 08:18:01
【问题描述】:

我想用 jquery 插件 timepicker 创建一个自定义指令。我没有在控制台中获取输入值,它显示未定义。

here's a plunkr

<table class="table table-bordered">
  <thead>
    <tr>
      <th>Time From</th>
      <th>Time To</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input type="text" ng-model="row1" size=6/ disabled>
      </td>
      <td>
        <input type="text"   ng-model="dup_row1 " size=6 timepicki/>
        {{dup_row1}}
      </td>
    </tr>

  </tbody>
</table>


var app = angular.module('myApp', []);
app.directive('timepicki', [

  function() {
    var link;
    link = function(scope, element, attr, ngModel) {
      element.timepicki();
    };

    return {
      restrict: 'A',
      link: link,
      require: 'ngModel'
    };
  }
])
app.controller('ctrl', function($scope) {
  $scope.row1 = "00:00"

  $scope.submit=function(){
    console.log($scope.dup_row1)
  }
});

【问题讨论】:

    标签: javascript jquery angularjs angularjs-directive jquery-ui-timepicker


    【解决方案1】:

    您发布的代码与您的 plunker 中的代码不同。

    AngularJS 开发者指南说;

    使用控制器:

    • 设置$scope 对象的初始状态。

    在上面的示例中,您在提交时记录了 $scope.dup_row1 的值,但您的控制器从不设置该值,因此它是未定义的。

    下面会打印“hello”到控制台;

    app.controller('ctrl', function($scope) {
      $scope.row1 = "00:00"
      $scope.dup_row1 = "hello"
    
      $scope.submit=function(){
        console.log($scope.dup_row1)
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-28
      • 2021-03-28
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多