我试图在角度js中创建一个自定义日历,我试图将一些值传递给它的孤立范围,但我没有在指令的范围内得到它无法弄明白为什么
app.directive("calendar", calendar);
function calendar() {
return {
restrict: "E",
templateUrl: "calendar.html",
scope: {
selected: "=",
show: "=",
avilDates: "="
},
link: function(scope) {
console.log('scope.avilDates' + scope.avilDates);
}
}
}
app.controller('addDetailExpController', function($scope) {
$scope.avilDates1 = [];
$scope.$watch('avilDates', function() {
console.log('avilDates', $scope.avilDates)
});
$scope.genAvailDate = function(exp) {
console.log('genAvailDate Working');
console.log(exp);
var result = [];
exp.options.forEach(function(option) {
if (typeof option.slots != 'undefined') {
option.slots.forEach(function(slot) {
if (typeof slot.dates != 'undefined') {
slot.dates.forEach(function(date) {
result.push(moment.unix(date.date).format("MM/DD/YYYY"));
});
}
});
}
});
console.log(result);
return result.reduce(function(a, b) {
if (a.indexOf(b) < 0) a.push(b);
return a;
}, []).map(function(a) {
return new Date(a);
});
}
});
<div ng-controller="addDetailExpController" ng-init="avilDates=genAvailDate(selected)">
<calendar selected="addDate.date" show="showdate" avilDates="avilDates" ng-show="showdate"></calendar>
</div>
我从genAvailDate
得到结果但是我无法在指令
答案 0 :(得分:0)
<div ng-controller="addDetailExpController" ng-init="avilDates=genAvailDate(selected)">
<calendar selected="addDate.date" show="showdate" avil-dates="avilDates" ng-show="showdate"></calendar>
</div>
尝试使用avil-dates
代替avilDates