CodeBean CodeBean - 4 years ago 162
Javascript Question

Angular js can't get value passed to directive

I was trying to create a custom calendar in angular js, and I was trying to pass some values to its isolated scope but am not getting it on the directive's scope can't figure it out why



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>





I am getting the result from
genAvailDate
but I can't get it inside the directive

Answer Source

<div ng-controller="addDetailExpController" ng-init="avilDates=genAvailDate(selected)">
  <calendar selected="addDate.date" show="showdate" avil-dates="avilDates" ng-show="showdate"></calendar>
</div>

Try using avil-dates instead of avilDates

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download