0

我无法从小部件中ng-bind="data1"捕获输入。ng-model="data1"通过单击并选择日期,ng-bind不会捕获所选日期。

<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"></script>
<script type="text/javascript">
    var Module = angular.module('myapp', []);
    myApp.directive('myapp', function datetimepicker() {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function(scope, element, attrs, ngModel) {
                element.datetimepicker({
                        minView: 2,
                        autoclose: true,
                        language: 'pt',
                        format: 'dd/mm/yyyy',
                        showMeridian: true,
                        startView: 2
                    })
                    .find('input')
                    .addClass("form-control");
            }
        };
    });
</script>
</head>
<body ng-app="myapp">
  <div id="datetimepicker" class="input-append date" ng-model="data1">
     <input ng-model="data1" type="text" datetimepicker></input>
     <p ng-bind="data1">
     <span class="add-on">
        <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
     </span>
 </div>
</body>
</html>
4

1 回答 1

0

您不应该myapp为您的模块和指令使用相同的名称。

在您的 html 中没有任何地方使用该指令。

此外, a<div>不能有 ng-model 指令,所以这一行是错误的:

<div id="datetimepicker" class="input-append date" ng-model="data1">

您的问题是您需要data1在控制器中进行初始化:

function($scope) {
  // Initialization
  $scope.data1 = '';
}
于 2015-02-21T02:22:34.730 回答