AngularJS not updating numbers

Starting out with Angular, my first project involves creating a system that highlights and iterates over rows and then, when clicked, iterates over columns. However, I'm encountering an issue where the numbers are not changing in my $interval function. I suspect it may be due to making too many calls to the JSON data. The values that should change are $scope.rowSelected and $scope.columnSelected. The error message I'm seeing is:

angular.js:13642 TypeError: fn is not a function
    at callback (angular.js:12456)
    at Scope.$eval (angular.js:17378)
    at Scope.$digest (angular.js:17191)
    at Scope.$apply (angular.js:17486)
    at tick (angular.js:12446)

Here is the view:

<!DOCTYPE html>
<html lang="en-us" ng-app="App">
    <head>
        <title>Click and Type</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta charset="UTF-8">

        <!-- load bootstrap and fontawesome via CDN -->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />


        <!-- load angular via CDN -->
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.js"></script>
        <script src="app.js"></script>


        <style type="text/css">
            .btn-info, .btn-danger, .btn-warning {
                height: 2em;
                width: 2em;
                font-size: 5.5em;
            }

        </style>
    </head>
    <body ng-controller="mainController"   ng-click="clickToSelect()">
        <div ng-controller="clickController">

        <header>
            <nav class="navbar navbar-default">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">Click and Type</a>
                </div>

                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#"><i class="fa fa-home"></i> Home</a></li>
                </ul>
            </div>
            </nav>
        </header>

        <div class="container">

            <div ng-controller="intervalController">

                <ul class="general_button" ng-repeat="letter in language[0].rows track by $index" ng-init="rowIndex = $index"> {{rowIndex}}
                    <button type="button" class="btn " ng-class="{true:'btn-warning', false:'btn-info'}[ isRowSelected( rowIndex ) ||  isColumnRowSelected( rowIndex,  columnIndex) ]" ng-repeat="single in letter track by $index" ng-init="columnIndex = $index"> 
                         {{columnIndex}}{{single}}
                    </button>
                </ul>

                <div  >
                    <button type="button" class="btn btn-danger">hello</button>
                     <h1 ng-mousemove="textArea = textArea + 1">Mouse over me!</h1>

                    <label for="inputlg">input-lg</label>
                    <input class="form-control input-lg" id="inputlg" type="text" value="{{ textArea + highlightedLetter }}">
                </div>

            </div>
        </div>


    </div>
    </body>
</html>

The module code is as follows:

var App = angular.module('App', []);
var theLanguage = 'english';
App.factory('jsonLanguage', function($http){
    var theLanguage = 'english';
    return {

        get: function(theLanguage){
            //var url = theLanguage + '.json';
            var url = 'english.json';
            return $http.get(url);
        }
    }

});
App.controller('mainController', function($scope, $http, $log, jsonLanguage, $interval) {
    $scope.language;

    jsonLanguage.get().then(function(res){
        $scope.language = res.data;
        $log.log($scope.language);
    });



    $scope.letterSelectedForText;
    $scope.rowOrcolumn = "row";
    $scope.rowSelected = 0;
    $scope.columnSelected = 0;

    //needs to able to pass function how done in angular


    $scope.callAtInterval = function() {
        console.log("$scope.callAtInterval - Interval occurred");
        if ($scope.rowOrcolumn == "row") {
            $scope.rowSelected = $scope.rowSelected + 1;
        }else if($scope.rowOrcolumn == column){
            if ($scope.columnSelected == $scope.language[$scope.rowSelected].length - 1) {
                $scope.columnSelected = 0;
                $scope.rowSelected = $scope.rowSelected + 1;
                $log.log("end of column");

            }else {
                $scope.columnSelected = $scope.columnSelected + 1;
                $log.log("add one column");
            }
         }
    };
//onclick switch rowOrColumn


    $scope.clickToSelect = function(){

        if ($scope.rowOrcolumn == "row") {

            $scope.rowOrcolumn = "column";

        }else if($scope.rowOrcolumn == "column"){

                $scope.letterSelectedForText = $scope.language[$scope.rowSelected][$scope.columnSelected];

                //reset
                $scope.rowOrcolumn = "row";
                $scope.rowSelected = 0;
                $scope.columnSelected = 0;          
        };
    };
    $scope.isRowSelected = function( rowIndex ) {
        if ($scope.rowOrcolumn == "row" && rowIndex == $scope.rowSelected) {
            return true;
        } else {
            return false;
        }


    };
    $scope.isColumnRowSelected = function(rowIndex, columnIndex) {
        if ($scope.rowOrcolumn == "column" && rowIndex == $scope.rowSelected && columnIndex == $scope.columnSelected) {
        console.log("rowindex" + rowIndex + $scope.rowSelected + "columnIndex" +columnIndex + $scope.columnSelected);
        return true;
        }else {
            return false;
        }
    };
    $scope.timeOfInterval = 2000;
$interval($scope.callAtInterval(), $scope.timeOfInterval);
});
App.controller('intervalController', function($scope, $log) {
    this.$log = $log;

});

App.controller('clickController', function($scope, $log) {
    $scope.$log = $log;
    var coll = document.getElementsByClassName("btn-danger");
    var highlighted = angular.element(document.querySelector(".btn-danger"));
    $log.log($scope.highlightedLetter = highlighted.text())
});

If you have any tips or advice on this topic, it would be greatly appreciated. Thank you!

Answer №1

The issue lies in the code snippet $scope.columnSelected + 1;. It seems that you forgot to assign the result of this expression back to $scope.columnSelected. Additionally, it is recommended to modify

$interval($scope.callAtInterval(), $scope.timeOfInterval);
to
$interval($scope.callAtInterval, $scope.timeOfInterval);

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

Encountering a null object reference error in AngularJS when using Internet Explorer

Issue: Encountering an error when AngularJS is being loaded in Visual Studio 2015 via an intranet URL. The error is occurring in the AngularJS library at these specific lines: line 7: if(H(b)||Ta(b)) (for angularjs.min.js) line 322: } ...

JavaScript Date behaving oddly

While working with Javascript, I encountered a puzzling issue involving the Date object. date1 = new Date(1970, 1, 1); date2 = new Date("1970-01-01T13:00:00.000Z"); console.log(date1.getYear()); //70 console.log(date1.getMonth()); //1 console.log(date1.g ...

Convert object to JSON format using AJAX request to a PHP file

Despite receiving a 200 green response, my data is still not getting written to the json file and it remains blank. The JavaScript: $(function() { $('form#saveTemp').submit(function() { let savdAta = JSON.stringify($('form#save ...

Checking the existence of a data attribute in plain JavaScript: A simple guide

Is there a way to determine the existence of an HTML5 data attribute using vanilla JavaScript? I attempted the following code snippet but unfortunately, it did not produce the desired result. if(object.getAttribute("data-params")==="undefined") { ...

Update angular2 to the latest 2.4.1 release, moving up from version 2.1.1

My goal is to upgrade my Angular2 version from 2.1.1 to 2.4.1 I started with this seed project. This was my original package.json content: { "name": "angular2-webpack-starter", "version": "5.1.1", "description": "An Angular 2 Webpack Starter ki ...

Data entry and a dropdown menu

Looking to add a dynamic numeric input that changes based on a select box choice. The numeric input will have a specific range based on the selected option from the select box. For instance: If option2 is selected, the numeric input range will be from 2 ...

Struggling to implement translation in Angular with Angular Translate

$scope.barChartData.labels.push(moment(currentDate).format("YYYY-MM-DD") + " $filter('translate')('To')" + moment(currentDate).add(4, 'days').format("YYYY-MM-DD")); Currently attempting to translate the word "To" ...

Arranging elements within an outer array by the contents of their inner arrays

I need help organizing an array based on the alphabetical order of a specific value within the inner arrays. For example: I want to sort this array by the prefix "old," so old A, old B, etc. const array = [ { personName: "Vans", personTags: ["young", " ...

Adjust the flexslider to transition to a new slide when hovering over the thumbnails

I have a flexslider with thumbnails like this ; https://i.stack.imgur.com/9bfC2.jpg I am looking to change the slide when the user hovers over the thumbnails. How can I achieve this functionality? Here is the jQuery code I am currently using to set up th ...

Updating the URL path within a JS file while copying using angular, grunt, and grunt-rebase

Currently, I am in the process of developing a project that incorporates foundationApps using Angular as its base. Within the directives, there are references to template paths like the example below: templateUrl: 'components/accordion/accordion.htm ...

Limiting drag and drop in Three.js with specified distance thresholds

Is there a way to restrict the distance an object can be dragged and dropped in Three.js using DragControl? I am looking to set a maximum distance from the object's original position to prevent users from dragging it too far. ...

Ways to hide the value from being shown

I have integrated jscolor (from jscolor) to allow users to pick a color with an input field. However, I am facing issues in styling it as I'm unable to remove the hex value of the selected color and couldn't find any relevant documentation on av ...

How to use jQuery to target the second or any desired div element with a specific class

I'm having trouble with something seemingly simple Let's say we are looking for a class called .contentdiv, for example. I am trying to target the second or nth occurrence of the .contentdiv class in a document and retrieve the HTML of that spe ...

Extract data from recurring rules

I am dealing with an object that is structured like this: const input = { "recurrence": { "rrule": [ "RRULE:FREQ=DAILY;UNTIL=20230606T133000Z" ], } }; My goal is to extract the value stored in FREQ and determ ...

Mastering the proper utilization of document.readyState in conjunction with Selenium

I am exploring a method to automatically scroll down a page that loads content dynamically as it is scrolled, ensuring everything is loaded before interacting with it using Selenium. I came across this code originally written for c#, which I have converte ...

Is there a simpler way to retrieve data from PHP or to efficiently filter the data once it's been retrieved?

Creating a business directory website involves fetching data from a database. The issue arose when attempting to apply a function uniformly to all boxes, as only the first one with the specified id would function correctly. To address this problem, the fol ...

How can I eliminate HTML elements from a string using JavaScript?

Currently, I am utilizing the rich text editor feature of the primeng library. It automatically converts any text I input into HTML format. However, there are instances when I need to display this content in plain text. Is there a straightforward method in ...

Enhancing Numbers with JavaScript

What I'm Looking for: I have 5 counters on my webpage, each starting at 0 and counting upwards to different set values at varying speeds. For example, if I input the values of 10, 25, 1500, 400, and 500 in my variables, I want all counters to reach t ...

What is the number of steps jQuery animates in?

Exploring my creative side, I decided to create my own custom animate function. Struggling to achieve a seamless animation effect, unlike the smooth transitions produced by jQuery. I'm curious about the formula they utilize to determine the ideal num ...

`Switching the selection in ng-selected`

I am having trouble toggling ng-selected options in Angular. I have tried the following approach: <select ng-model="datacut.ages" multiple> <option value="" disabled="disabled">Please Select</option> <option value="0-15" ng-clic ...