Unexpected results occur when accessing data in $uibModal.open() within Angular JS causing it to

Here is the code snippet that is causing the issue of returning undefined items in AngularJS:

App.js code

console.log('single page application script is working');
var myApp = angular.module("demoApp", ["ngRoute", 'ui.bootstrap','chart.js']);
myApp.controller('CtrlOne', CtrlOne);
myApp.controller('CtrlTwo', CtrlTwo);
myApp.controller('LocationController', LocationController);
myApp.controller('GridController', GridController);
myApp.controller('PaginationDemoCtrl', PaginationDemoCtrl);
myApp.controller('ViewProductController', ViewProductController);

var configFunction = function ($routeProvider, $httpProvider) {
    $routeProvider.
        when('/grid', {
            templateUrl: 'SPA/Views/Grid.html',
            controller:GridController

        })
        .otherwise({
            redirectTo: function () {
                return '/grid';
            }

        });
}
configFunction.$inject = ['$routeProvider', '$httpProvider'];
myApp.config(configFunction);

GridController.js

var GridController = function ($scope, $uibModal) {
    $scope.data = {
        lowStockData: {
            totalItems: 726,
            currentPage: 1,
            itemsPerPage: 10,
            data:[]

        }
    };
    function getData() {
        $scope.data.lowStockData.data = []; //initialize the data inside the lowStockData to empty
        for (var i = 0; i < $scope.data.lowStockData.itemsPerPage; i++) {
            var currentLocation = $scope.selectedLocation.Location;

            var rndNum = ($scope.data.lowStockData.currentPage * 10) + i;

            $scope.data.lowStockData.data.push({
                SKU: "SKU" + rndNum,
                ProductTitle: "Product Title" + rndNum,
                OnOrder: rndNum * 2,
                Due: rndNum - 1,
                StockLe: rndNum,
                Location:currentLocation

            });
        }
    }
    getData();
    $scope.pageChanged = function () {
        getData();

    }
    $scope.$watch('selectedLocation', function () {
        console.log($scope.selectedLocation.Location);
        $scope.data.lowStockData.currentPage = 1;
        getData();

    });
    $scope.openProduct = function (product) {
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: '/SPA/Views/ViewProductWindow.html',
            controller: 'ViewProductController',
            size: "",
            resolve: {
                items: function () {
                    console.log(product);
                    return product;
                }
            }
        }

        );
        modalInstance.result.then(function () {
            $scope.data.lowStockData.selectedItem = selectedItem;
        }, function () {
            console.log('Modal dismissed at: ' + new Date());
           // $log.info('Modal dismissed at: ' + new Date());
        });
    }



}
GridController.$inject = ['$scope','$uibModal'];

ViewProductController.js

console.log("View product controller is working");
var ViewProductController = function ($scope, $uibModalInstance, items) {
    console.log(items);
    $scope.selectedProduct = items;
    $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
    $scope.series = ['Series A', 'Series B'];
    $scope.data = [
        [65, 59, 99, 73, 22, 11, 40],
        [76, 23, 65, 88, 45, 88, 98]
    ];

}
ViewProductController.$inject = ['$scope','$uibModalInstance'];

Encountering an issue where clicking on 'open product' opens a modal with a graph, but $scope.selectedProduct = items; always returns undefined. Having trouble understanding why the items object is returning undefined from the resolve block $uibModal.open(). Can anyone offer some insight?

Answer №1

Your ViewProductController has a dependency on 'items', but it has not been added to the $inject array for resolution as a dependency.

Update it as follows:

ViewProductController.$inject = ['$scope','$uibModalInstance', 'items'];

Now 'items' has been added as a dependency and will be resolved for ViewProductController.

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

Slow loading time when switching between items in the drop-down menu from the Main Menu

Visiting my website at europebathroom.com, you will notice a horizontal main menu with dropdown functionality. When hovering over a menu item, the corresponding dropdown appears seamlessly. Yet, sometimes quickly touching another menu item unintentionally ...

Questions about clarifying JS promises and async-await functions

After doing some reading on promises in JavaScript, I have come across conflicting information which has left me with a few basic questions. I have two specific questions that need clarification: Is it necessary for every function in JavaScript to be ca ...

“Unable to update value using Controller component in react-hook-form”

Currently, I am utilizing the react-hook-form in combination with MUI components. In order to incorporate the Select component, I have enclosed it within the Controller since direct registration is not possible. Although everything seems to be functioning ...

Python and JavaScript fundamental interaction

My current setup involves having a local HTML page named leaflet.html, which is being shown in an embedded browser within a python-tkinter application. Within the leaflet.html file, there exists a straightforward JavaScript code snippet that includes a fu ...

jQuery may not function properly in a dynamic content environment

I'm encountering an issue with my web application. I've developed a chat feature using Ajax, and I want it to load when a button is clicked. The functionality works, but the dynamic data loaded doesn't seem to be compatible with jQuery. Aft ...

Having difficulty implementing pagination functionality when web scraping using NodeJS

Currently, I am creating a script that scrapes data from public directories and saves it to a CSV file. However, I am encountering difficulties when trying to automate the pagination process. The source code I am using includes: const rp = require(' ...

Instead of using a v-if condition, add a condition directly in the Vue attribute

Apologies for the unclear title, as I am unsure of what to name it with regards to my current issue, I am attempting to create a component layout using vuetify grid. I have a clear idea of how to do this conventionally, like so: <template> <v-fl ...

jQuery sorting function is utilized to organize a table after its rows have been modified through an ajax

My website features an election section that displays updated election numbers in real-time. Previously, users had to refresh the page to see new results. I have implemented code that utilizes a custom REST API to fetch live numbers and jQuery to dynamica ...

What is the correct method for integrating jQuery libraries into an Angular project version 10 or higher?

Currently, I am facing difficulties while attempting to install the jquery and jquery-slimscroll packages into an Angular project (version greater than 10). It appears that the installation of these packages has not been successful. In light of this issue, ...

The POST request functions smoothly in Postman, however, encounters an error when executed in node.js

Just recently I began learning about node.js and attempted to send a post request to an external server, specifically Oracle Commmerce Cloud, in order to export some data. Check out this screenshot of the request body from Postman: View Request Body In Pos ...

Unlock the App Store instead of iTunes Store using react-native-version-check

I am currently using react-native-version-check to trigger the opening of the app store or play store if an update is available. However, on iOS it redirects to the iTunes store instead of the desired AppStore location. Below is the code in question: ...

Having difficulty with loading images lazily in a jQuery Mobile app with LazyLoadXT feature

Struggling to incorporate lazy loading in my jQM app with Lazy Load XT v1.0.6. Oddly, images only appear when switching browser tabs, not while scrolling down. This happens on Firefox and Chrome. <img src="/img/default-img.jpg" data-src="/img/product/ ...

How can you automatically show the current time upon entering a page using React Native?

Is there a way to automatically display the current time when a user enters the page? I currently have code that only shows the current time when the TouchableOpacity is pressed, but I want it to update automatically as soon as the user arrives on the Ne ...

Error encountered with AngularJS code when attempting to load content from another page using ajax

I'm currently tackling a challenge with AngularJs and php. Whenever I try to load content from another page, AngularJs seems to stop working. Let me provide you with a sample code snippet to illustrate my issue. main-page.php <div id="form-secti ...

When the class name is identical, the click event appears to be malfunctioning

Why isn't the click event working in this code? What am I doing wrong? $(document).ready(function() { $('.dashboardList').click(function() { alert("hello"); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1. ...

The mesmerizing world of parallax animations and the smooth scrolling experience

I recently built a website using the SUPERSCROLLORAMA plugin, only to discover later that there are issues with parallax scrolling on iPad and iPhone. Now I'm trying to figure out how to solve this problem. It seems that events are disabled on these ...

Reading and extracting data from a massive XML document using Node.js

Currently, I am facing a challenge with an XML file that is quite large - exceeding 70mb. My goal is to parse this data in Node.js for potential data visualizations down the line. After giving it some thought, I decided that converting the XML file to JSON ...

I prefer to avoid generating the document structure while parsing with JSOUP

Utilizing the Jsoup API to parse a section of HTML using the Jsoup.parse() method. However, during parsing, it includes the document structure in the HTML content. For Instance: <p><a href="some link">some link data</a> Some paragraph c ...

Regular expression that matches a string with optional leading and trailing spaces and a hyphen in the middle

I need help creating a JavaScript regex that can match strings like the examples provided. The string may have whitespace at the front, back, or both but not within the string itself. Examples: 'Z5LW-KRT2' MATCH ' Z5LW-krt2' ...

What is the process for invoking an External Javascript Firestore function within a Typescript file?

Trying to figure out how to integrate a Firestore trigger written in an external JavaScript file (notifyNewMessage.js) into my TypeScript file (index.ts) using Node.js for Cloud functions. Both files are located in the same directory: https://i.stack.imgu ...