我无法将范围变量传递给此angularjs指令。指令(https://github.com/archsaber/angular-flatpickr)将其范围定义为:
var ngFlatpickr = angular.module('angular-flatpickr', []);
ngFlatpickr.directive('ngFlatpickr', [function () {
return {
require: 'ngModel',
restrict: 'A',
scope: {
fpOpts: '&',
fpOnSetup: '&'
},
我在自己的指令中使用此指令。它的用法如下:
<input ng-flatpickr fp-opts="dateOpts" fp-on-setup="datePostSetup(fpItem)"
ng-model="myStartDate">
我的指令代码定义了dateOpts和datePostSetup。我的问题是没有一个被调用。
function link($scope, element, attrs) {
$scope.dateOpts = {
dateFormat: 'Y-m-d',
placeholder: 'Change date..', // Default: 'Select Date..'
defaultDate: '2016-03-01 03:30:00 -0300',
onChange: function (selectedDates, dateStr, instance) {
// Do stuff on change
}
};
$scope.datePostSetup = function (fpItem) {
console.log('flatpickr', fpItem);
}