Angular JS is experiencing difficulty retrieving the passed value in the directive

While attempting to develop a custom calendar in AngularJS, I encountered an issue with passing values to the isolated scope within the directive. Despite my efforts, I am unable to access these values on the directive's scope and I am struggling to understand 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>

Although I am successfully obtaining results from genAvailDate, I am facing difficulties in retrieving this data within the directive itself.

Answer №1

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

Consider using avil-dates instead of avilDates

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for making a separate countdown clock for every element in a list?

I am facing an issue in my React application where I need to display a list of orders to the user for only 30 seconds each. Each order has a duration property set to 30 seconds: [ { ..., ..., duration: 30 }, { ..., ..., durati ...

Ways to retrieve data from an AJAX success callback function

Within my front end JavaScript application, I need to execute an ajax request in order to retrieve data from the server. Once this data is acquired, I aim to display it within the view. var retrievedData; $.ajax({ url:"/getDataFromServer.json", ty ...

Guide on iterating through multiple Objects while comparing key values with a string

My goal is to iterate through multiple objects, comparing the date_created key value of each object to a specific string. These objects are retrieved from an array that I can map over to display the results. Once I loop through each object, I want to push ...

Deselect the checkbox that was initially selected when an alternative checkbox option has been chosen

I am trying to implement a feature where there are 2 groups of checkbox options on the same page. Below is the code snippet: <div class="col-xs-12"> <label class="checkbox-inline"> <input type="checkbox" th:field="*{borrowerRace1}" th:val ...

Having difficulty displaying Zomato API data in infowindows using $.ajax

Struggling to populate infowindows with Zomato API data and facing issues with getting only the last item in the object. Attempted using a for loop with a closure and replacing "var" with "let", but no luck. Any advice to move forward would be much appreci ...

Having trouble with the functionality of the jQuery `has()` method?

Consider the following HTML code snippet: <div class="comment"> <span class="test">some content here</span> <p>Lorem ipsum</p> </div> <div class="comment"> <p>Lorem ipsum</p> </div> The ob ...

Updating data for a heatmap in Angular-Leaflet

My goal is to display a dynamic heatmap using the Angular-Leaflet directive. I have written the following code: getData().then(function (data) { $scope.heat.index = 0; $scope.heat.data = data; $scope.layers.overlays.heat = { name: "Hea ...

JavaScript causing display issues with Unicode characters

convert.onclick = function() { for (var i = 0; i < before.value.length; i++) { after.value += "'" + before.value.charAt(i) + "', "; } } <textarea id="before" type="text" name="input" style="width:100%;">* ...

Error: The code is trying to access the property 'string' of an undefined variable. To fix this issue, make sure to

I encountered an issue after installing the https://github.com/yuanyan/boron library. The error message I received is: TypeError: Cannot read property 'string' of undefined Error details: push../node_modules/boron/modalFactory.js.module.expor ...

Updating a Json array by including a new property using the Gson library

Using Gson, I am serializing a list of objects in the following manner: String responseMessage = new Gson().toJson(pages.get(pagenumber)); Now, I want to include an additional property that can be accessed in JavaScript, which is not related to the list ...

AngularJS: Move forward with controller execution after completion of a looped service method

Currently, I am implementing a networkService in Angular which is responsible for looping while the internet connection is unavailable. The goal is to resume execution once the connection is restored. Below is an example of a controller: MyApp.controller ...

What are some ways to implement smooth scrolling when a navigation link is clicked?

I have a total of 3 links in my navigation bar and every time they are clicked, I want the page to smoothly scroll down to their designated section on the webpage. Although I have already set up the anchors, I lack experience in scripting to create the smo ...

What is the best way to interrupt an animation and restart it?

On my webpage, I have implemented some anchors and links that navigate to these anchors. When I click on a link, the background-color of the anchor changes. I use animation to gradually fade out this color over 10 seconds - starting with white and then rem ...

Issue encountered while fetching data from SQL database in a Node.js application

After successfully connecting the database to my node js project, I encountered an issue when attempting to retrieve data using the get operation. Despite the connection working fine, I was unable to resolve the error that occurred. Establishing the SQL c ...

Using AngularJS to iterate through a nested array with ng-repeat

Hey everyone, I've been working on a project where I have an array called menu[] with nested arrays called flavors[] within it. My goal is to calculate the total price of all active items and flavors in the menu. While I was able to successfully calcu ...

Instructions on obtaining a distinct daily array from the weather API array that provides a detailed 5-day weather report every 3 hours

Seeking assistance with my weather app development on React using axios with the openweathermap.org API. Currently stuck on getting data formatted in a specific way from the 5-day forecast it provides, totaling 40 reports over the 5 days. The API response ...

Prevent the propagation of a particular CSS class's inheritance

I need to make modifications to an existing HTML5 app that features two unique themes. Here's an example of the current structure: <body class="theme1 theme2"> <div id="div1">I'm satisfied with both themes</div> <di ...

What is the best approach to transition a monolithic MEAN stack application to a Microservices architecture?

Our team has created a comprehensive MEAN stack application for streamlining employee and inventory management in the workplace. What's the best way to utilize the Employees functionality as a separate service from Inventory? ...

What is the most efficient way to retrieve a document from pouchdb that includes the revision attribute?

I am currently developing an application using the electron framework and integrating pouchdb. As certain values in my database are dynamic and constantly changing, I am looking for a way to track these changes without having to create new documents for ea ...

Encountering a "Window is undefined" error while trying to load a node_module package within a

I am attempting to incorporate the pickr package (a color picker library) into my nuxt.js application. However, I am encountering an error during import, specifically "window is undefined". Below is the code snippet: <script> import Pickr from &apo ...