Is it possible that Angular 1.0.8 code is incompatible with version 1.6.5?

Just started dabbling in angular-js today and decided to experiment with some older examples.

I have a backend api that provides me with a json list. I am trying to fetch this data and display it on my webpage.

The examples I found were built using version 1.0.8 of angular-js and they work perfectly. However, when I attempt to replicate the same functionality using version 1.6.5, nothing seems to work. What could be causing this issue? How can I resolve it?

Files

function Books($scope, $http) {
$http.get('http://localhost:8080/book-manager/bookslist.json').success(function(data) {
$scope.books = data;
});
}
<!DOCTYPE html>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Angular</title>
<!-- 1.0.8 Working -->
<script src="angularjs/1.0.8/angular.min.js"></script>
<!-- 1.6.5 Not Working, Why? -->
<!-- <script src="angularjs/1.6.5/angular.min.js"></script> -->
<script src="count.js"></script>
</head>
<body>
<div ng-controller="Books">
I have {{books.length}} books!
<ul class="books-container">
<li ng-repeat="book in books">{{book.name}}</li>
</ul>
</div>
</body>
</html>

Answer №1

One significant update was the revised method of declaring a controller in your Angular application. To implement this, you must have your primary ng-app module and incorporate a controller into it (maintaining the functionality of the Books function as before).

count.js

angular.module('mainAppExample', []).controller('Books', Books);
function Books(){}

It's essential to include the ng-app directive, which serves as your root module (allowing the addition of multiple controllers, filters, and other directives). Typically, this directive is placed within a root element tag such as <html> or <body>:

books.html

<body ng-app="mainAppExample">
    <div ng-controller="Books">
        I have {{books.length}} books!
        <ul class="books-container">
            <li ng-repeat="book in books">{{book.name}}</li>
        </ul>
    </div>
</body>

Answer №2

The range between versions 1.0 and 1.6 represents a significant leap with numerous changes. The initial legacy version to focus on is 1.2x, followed by transitions to 1.3, then 1.4 leading up to 1.5. It is highly recommended to carefully examine the changelogs available here:

https://github.com/angular/angular.js/blob/master/CHANGELOG.md

It is crucial to understand the breaking modifications that have been introduced.

From version 1.5 onwards, promises are utilized. Therefore, you should implement something like:

$http.get(URL).then(function(data) {
        //handle success 
    }, function (error) {
        //handle error
    });

This issue does not end there; it is imperative to evaluate all alterations thoroughly.

I personally suggest exploring Angular (as opposed to AngularJS). Even for smaller projects, embracing new knowledge can be beneficial.

Edit: For beginners in AngularJs, I would advise against investing significant time in learning it as its lifespan may be limited. Instead, consider transitioning to Angular (version 4+).

Answer №3

Achievement is no longer recommended. It is best to utilize 'then' instead.

function BookList($scope, $http) {
    $http.get('http://localhost:8080/book-manager/bookslist.json').then(function(data) {
        $scope.books = data;
    });
}

If you are receiving a complete response object in version 1.6.5, consider the following adjustment:

function BookList($scope, $http) {
    $http.get('http://localhost:8080/book-manager/bookslist.json').then(function(response) {
        $scope.books = response.data;
    });
}

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

The leakage of requested data in NodeJS is spreading through HTTP requests

I've set up a basic webserver using Express.js. This server is designed to serve files that are created dynamically by processing data fetched from a third-party API. Here's the code for my webserver: it utilizes builder.js to construct the file ...

C# implementation of the btoa function from JavaScript

I am in need of assistance recoding a JavaScript function to C# that makes use of the btoa method to convert a string of Unicode characters into base64. The challenge lies in ensuring that the encoding used in both languages is identical, as currently, the ...

Angular 2+ enables the creation of dynamic folders and allows for uploading multiple files to the server in a seamless

Can an Angular application be developed similar to FileZilla or Core FTP for uploading files and folders to the server via FTP? I need a way to upload files and folders through the admin panel instead of relying on external applications like FileZilla. ...

How can I add a string before a hashtag(#) in AngularJS URLs?

Can we add a prefix to the # symbol in angular.js URLs? For instance: let's say we have a site: http://example.com/ then when I click on the CSharp page, it redirects to http://example.com/#/csharp when I click on the AngularJS page, it redi ...

What is the best way to implement dynamic filtering in Nest JS?

I have a unique software application that requires dynamic filtering, but I am facing a challenge with different fields where I cannot specify any field specifically. Can you provide me with some guidance or articles on how to tackle this issue? Here is a ...

Effortless Like/Unlike feature with a text button option enhanced with ajax functionality and

Struggling to create a simple Like/Unlike button in PHP without refreshing the page. Despite an abundance of tutorials on AJAX and jQuery, implementation remains elusive due to lack of experience. Uncertain where each part of the code goes within which fil ...

Best practices for securely storing access tokens in React's memory

I'm on a quest to find a secure and efficient way to store my access token in a React application. First and foremost, I have ruled out using local storage. I don't see the need to persist the access token since I can easily refresh it when nece ...

Having trouble transferring files to an unfamiliar directory using Node.js?

const { resolve } = require("path"); const prompt = require('prompt'); const fsPath = require('fs-path'); // Retrieve files from Directory const getFiles = dir => { const stack = [resolve(dir)]; const files = []; whi ...

Is it possible to conceal an HTML form once it has been submitted

I have a form on my website that sends the entered information to a PHP script which then emails me the details. I've implemented JavaScript form validation and jQuery Ajax to ensure the page doesn't need to be reloaded. Here is the HTML code fo ...

Discovering the required rotation angle for an object to directly face another using JS HTML5 CANVAS

Hey there, I'm currently working on a game project in Javascript where I have a player and a cursor. I already know the positions of both objects, but what I need help with is determining the angle in degrees or radians that the player needs to rotate ...

Protractor encounters an "Error starting WebDriver session" message

After starting a server with webdriver-manager start, encountering an error when attempting to run protractor: Using the selenium server at http://127.0.0.1:4444/wd/hub [launcher] Running 1 instance of WebDriver ERROR - Unable to initiate a WebDriver sess ...

An array comparison function in JavaScript

Similar Question: Using jQuery to compare two arrays I'm looking for a Javascript or jQuery function that can check if one array contains all the values of another array. The second array may have more values than the first. The function should ...

vue mapGetters not fetching data synchronously

Utilizing vuex for state management in my application, I am implementing one-way binding with my form. <script> import { mapGetters } from 'vuex' import store from 'vuex-store' import DataWidget from '../../../../uiCo ...

Creating an Angular reactive form with checkboxes and initializing a formArray with an existing array

I have a dynamic array of LkBoardTypeList fetched from a server. My goal is to push that array to form an array upon initialization, essentially displaying checkboxes based on the Board's name or ID in the array. I know how to push an empty array in r ...

Creating a merged object from a split string array in TypeScript

I possess an array containing objects structured as follows; const arr1 = [ {"name": "System.Level" }, {"name": "System.Status" }, {"name": "System.Status:*" }, {"name": "System.Status:Rejected" }, {"name": "System.Status:Updated" } ] My object ...

Unable to bind knockout dropdownlist data during an ajax request

Trying to connect a dropdownlist in knockout with MVC 4. Below is the code snippet: Action public JsonResult GetUserTypes() { using (QuestApplicationEntities db = new QuestApplicationEntities()) { var usertypes = (from ...

How can animations be disabled in Angular/Javascript?

I have been assigned the task of developing an Angular component for my company's applications that will include a toggle to disable all animations within the app for accessibility purposes. It is important to note that I am unable to go into each in ...

Strange symbols keep appearing in my output from PHP

My current task involves generating a SQL query based on some inputs. I have a predefined SQL statement, in which I perform certain replacements, that will use these inputs to generate the required SQL through an ODBC connection. For now, I have stored th ...

Learn how to dynamically change a class name with JavaScript to alter the color of a navbar icon

I have little experience with javascript, but I want to make a change to my navbar icon. Currently, my navbar has a black background with a white navbar icon. As I scroll the page, the navbar background changes to white and the font color changes to black. ...

The "Mongoose 'model is not a constructor' error" is causing issues

It appears that I am encountering a rather common error. Despite reviewing previous questions, none have been able to resolve my issue. The typical mistakes involve using module.export instead of module.exports, and initializing a new schema instance inste ...