Angular dependencies cannot be injected because $scope is not defined

Currently, I am utilizing the latest version of angularjs (1.3.3):

I have integrated 3 JavaScript libraries into my project.

<script src="framework/jquery-1.9.1.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js"></script>
<script src="framework/tm.pagination.js" ></script>

This is a snippet of my JavaScript code:

angular.module('myApp', ['tm.pagination']).controller('testController', [function($scope, $http){
    var reGetProducts = function(){

        var postData = {
            currentPage: $scope.paginationConf.currentPage,
            itemsPerPage: $scope.paginationConf.itemsPerPage
        };


        // console.log(postData);
        $http.get('data/mybook.json').success(function(data){

            $scope.paginationConf.totalItems = data.total;

            $scope.products = data.items;
        });
    };


    $scope.paginationConf = {     
        currentPage: 1,
        itemsPerPage: 15      //issue arises here as $scope is undefined
    };

    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', reGetProducts);
}]);

An error is being encountered:

error: $scope is undefined @http://localhost:8080/table.html:55:13 invoke@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:4129:14 $ControllerProvider/this.$get</</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:8370:11 nodeLinkFn/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:7618:13 forEach@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:330:11 nodeLinkFn@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:7617:11 compositeLinkFn@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:7003:13 compositeLinkFn@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:7006:13 publicLinkFn@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:6882:30 bootstrapApply/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1439:11 $RootScopeProvider/this.$get</Scope.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:14204:16 $RootScopeProvider/this.$get</Scope.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:14302:18 bootstrapApply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1437:9 invoke@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:4129:14 bootstrap/doBootstrap@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1435:1 bootstrap@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1455:1 angularInit@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1349:5 @https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:25746:5 jQuery.Callbacks/fire@http://localhost:8080/framework/jquery-1.9.1.js:1037:10 jQuery.Callbacks/self.fireWith@http://localhost:8080/framework/jquery-1.9.1.js:1148:7 .ready@http://localhost:8080/framework/jquery-1.9.1.js:433:1 completed@http://localhost:8080/framework/jquery-1.9.1.js:103:4

It seems like I have properly declared $scope while injecting the variable.

Answer №1

It's important to remember to include $scope in your declaration, before it's injected as a parameter:

angular.module('myApp', ['tm.pagination']).controller('testController', [
    '$scope', 
    function($scope, $http){

        //...continue with the rest of your code...

    }]);

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

Angular ngClick on a rectangle within an SVG element

Need to trigger angular click functions on rects in an svg. <rect data-ng-click="scrollToAnchor('siteHeader')" fill="#010101" width="501" height="81"></rect> Here's the function: $scope.scrollToAnchor = function(anchor) { $a ...

Send functions from the back-end Node to the front-end Angular

Introduction I am currently working on a project that involves verifying email addresses within an API in order to grant users access to a restricted section. To accomplish this, I have developed backend node code with three functions built using Node and ...

Tips for creating a custom script in my React Native application

My React Native app requires a script to generate static files during the release process. The app is a game that utilizes pre-computed boards, which are resource-intensive to compute. Therefore, I am developing a script that will create these boards and s ...

Obtain the child's identification number and include it in the parent element as an ARIA

I need assistance with a JavaScript (or jQuery) function to dynamically add an 'aria-labelledby' attribute to parent <figure> elements based on the ID of the <figcaption>. I have multiple images and captions set up in <figure>&l ...

Removing Embedded Json Element from a Collection in AngularJS HTML

In my JSON Collection, I want to display the Email ID that is marked as IsPreffered = TRUE using AngularJS HTML without using JavaScript. This is my JSON Collection: { "user" : [ { "Name" : "B. Balamanigandan", "Email": [ ...

Bootstrap 4 collapse is experiencing some issues as it is not collapsing smoothly. It seems to pause halfway before

Why is this collapse stopping in half before collapsing completely? I have 5 divs collapsing at once, could that be the issue? The example on W3 schools works fine... Should I consider changing the collapse to a panel instead? Visit W3 Schools for more i ...

Encountering difficulties with properly storing an array in MongoDB using Node.js and Mongoose

Can you point me in the right direction on how to properly store an array of data in mongodb using node/mongoose? I'm currently facing an issue where all my data is being saved as the first value in the array. Here's a snippet of my code: const ...

Create a hover effect on HTML map area using CSS

Is it possible to change the background color of an image map area on hover and click without using any third-party plugins? I attempted the following code: $(document).on('click', '.states', function(){ $(this).css("backgro ...

Introducing the brand new feature: Video Mute Button!

Currently, I am working on implementing a mute button for a video on my webpage. The background of my page consists of a looping video with no other content, but the sound becomes quite bothersome after a while. While I have managed to find a button to pau ...

Ways to detect when the window printing process has been completed

Within my application, I attempted to generate a voucher page for the user using the following code: var htm ="<div>Voucher Details</div>"; $('#divprint').html(htm); window.setTimeout('window.print()',2000); The &apo ...

What is the measurement of the width of a specific DOM element?

Is it possible to determine the width of a DOM element? Specifically, I need to find out the width of a table cell (td) that may have varying widths based on the length of text inside it. Ideally, I prefer a solution that utilizes the jQuery library, but ...

Exploring the functionalities of command line arguments in Vue.js

Is there a way to set command line arguments for a Vue.js application? I am utilizing Vue 3 on the frontend which interacts with a Python backend (Flask) using Axios. Currently, I am defining the baseURL for Axios in my main.js file as follows: import axio ...

Display only the selected index and conceal the rest

I am facing an issue where I have added a label and input in ng-repeat. The functionality works fine when the user clicks edit to show the input and hide the label. However, the problem arises when the user clicks on the new button as it displays the new i ...

What makes this factory function able to automatically handle the resolution of the "Factory" object?

I'm currently examining some code and trying to understand how this particular line handles the "factory" concept, which is essentially a delegate taking a "Type" and returning an object. Unfortunately, I'm struggling to articulate my question be ...

Updating the view manually is necessary when using AngularJS $routeProvider and resolve feature

I am facing issues with $routeProvider in updating the view automatically. Currently, I am working on converting a chapter 22 example from Adam Freeman's Pro Angular book, originally based on Deployd, to Express-Mongo. Strangely, the automatic refres ...

Ensure that newly added elements are aligned with the settings of the slide's

I've encountered an issue with my jQuery slider that affects a div's CSS on slide. Everything works as expected, except when I add a new div, the settings from the slider aren't applied to the new div until the slider is moved again. HTML ...

undefined is returned within a nested return statement

I need to pass some specific props, such as mapObject={this.props.mapObject} details={this.props.parsedData.categories[key], to another component called Item. However, I am encountering an issue where I receive a TypeError: this is undefined. Initially, t ...

Show and hide components in React by simply clicking on them

I'm looking to achieve the following: If the component is visible, clicking away from it should hide the component. If the component is hidden, clicking on it (or any area that it would occupy if visible) should show the component. Is there a way to ...

Issue with collapse functionality in Bootstrap not activating after using append()

Whenever the ajax call is successful, I am appending the content to the element with the id #special-contents. However, upon page load, the collapse button does not expand the panel. Below is my JavaScript code: $.ajax({ url: `${URL}/promotions/`, ...

NodeJS Post Request Issue: Parsing Numbers in URL Parameters Resulting in NaN

I'm fairly new to working with NodeJS. Currently, I am facing an issue where all the integers in the parameters are being passed as NaN when making a POST request. In the snippet below, you can observe that the parameters have actual numbers assigned ...