0

我尝试使此脚本适用于 2 个不同的日期:

http://fiddle.jshell.net/yXjkq/1/

它适用于第一个,但不适用于第二个。我试图理解为什么?

JavaScript:

var mySecondModule = angular.module('MyReportModule', []);

function TheReportCtrl($scope) {
    $scope.selectedDate = "Aladdin";
    $scope.selectedDate2 = "Aladdin2";
}
mySecondModule.directive('datepicker', ['$parse', function($parse) {
    return {
        restrict: "A",
        link: function(scope, element, attrs) {
            //using $parse instead of scope[attrs.datepicker] for cases
            //where attrs.datepicker is 'foo.bar.lol'
            parsed = $parse(attrs.datepicker);
            $(element).datepicker({
                onSelect: function(dateText, inst) {
                    scope.$apply(function(){
                        parsed.assign(scope, dateText);
                    });
                }
            })
        }
    }
}]);

HTML:

<div ng-app="MyReportModule">
  <div ng-controller="TheReportCtrl">

   <input type="text" datepicker="selectedDate" />{{selectedDate}} 
   <input type="text" datepicker="selectedDate2" />{{selectedDate2}} 

</div>
</div>
4

1 回答 1

1

将其更改parsed = $parse(attrs.datepicker);var parsed = $parse(attrs.datepicker);对我有用。请尝试让我们知道。

于 2013-04-01T23:55:24.983 回答