Error: [$controller:ctrlreg] - The controller registration has failed

I am currently exploring the world of AngularJs and attempting to display options from a json file. However, I keep encountering the following error message:

"Error: [$controller:ctrlreg]"

Below is the code snippet I am working with:

var sj = angular.module("factApp", []);

(function(app){
    "use strict";
app.controller('appController', function ($scope, $http){
    $http.get('values.json').success(function (datos){
        $scope.datos = data;
        });
});
});
{
  "orders": {
    "odc": [
      {
        "id": "ABA",
        "coupons": [
          "1XY",
          "2XY",
          "3XY"
        ]
      }
    ]
  }
}
<!DOCTYPE html>
<html lang="en>
<div class="row" ng-app="factApp" ng-controller="appController">
    <h1>Cupones</h1>
    <ul>
        <li ng-repeat="data in datos">
        <p>Orden: {{data.id}}</p><br>
        <p>Cupones {{data.coupons}}</p>
        </li>
    </ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="testjson/fuctury.js"></script>

Could you please help me identify what I am doing wrong in my code? Any assistance would be greatly appreciated. Thank you in advance.

Answer №1

The issue with your code is that you need to access the data property of the response and use .then instead of success

sj.controller('appController', function($scope, $http) {
  $http.get('values.json').then(function(response) {
    $scope.data = response.data.orders.odc;
    console.log($scope.data);
  });
});

DEMO

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

Decoding Azure JSON Responses with C#

Check out the JSON Response displayed below: [ { "faceRectangle": { "top": 214, "left": 472, "width": 450, "height": 450 }, "faceAttributes": { "age": 19.0, "emotion": { "anger": 0.0, "contempt": 0.0, ...

convert a string to JSON format using Node.js Express

Currently, I am viewing some string data in a browser that has been processed using python-node js express. The data looks something like this: In order to manipulate the data more effectively, I would like to convert it into JSON format that follows this ...

How can I adjust the column width in OfficeGen?

Currently, I am utilizing officeGen for the purpose of generating word documents. <sup> let table = [ [ { val: "TT", fontFamily: "Times New Roman", }, { val: "Ten hang", ...

Identifying the specific npm script command that was executed

My index.js file contains scripts that can be executed like the ones below: "scripts": { "lint": "eslint .", "serve": "firebase emulators:start --only functions", "inspect": "firebase emulators:start --inspect-functions", "deploy": "fire ...

Utilizing "this" correctly within JavaScript objects

Can someone help me understand how to access enums.ROCK within the prop in the code snippet below? I keep getting an error that says Uncaught TypeError: Cannot read property 'enums' of undefined. Please pay attention to the comment ERROR LINE. c ...

Converting Basic JSON Data into an SQL SELECT Query

Presented is the subsequent JSON data: DECLARE @json NVARCHAR(MAX) SET @json = N'[ {"@odata.context":"http://www.example.com","value":[ {"financialmovements_ID":1,"Data":"2020-02-10T00:00:00Z","ES":"E","Descri\u00e7\u00e3o":"FIV-005 3& ...

A Guide to Deserializing a JSON Object Containing a Huge Integer Value in .NET C#

I'm having an issue deserializing a JSON response from the endpoint https://api.huobi.pro/market/history/trade?symbol=btcusdt. The problem is that the response contains a very large number that exceeds the capacity of ulong in C#. This is resulting in ...

Exploring the Power of AngularJS' $resource with JAX-RS Integration

Recently, I developed a small web application using AngularJS, JAX-RS, and Hibernate. While I am able to retrieve objects of my type 'Plugin' successfully, I am facing issues with saving them. Upon inspecting the object on the server, I noticed t ...

I am currently in the process of conducting an automated test focused on the creation of a new Facebook account

I am currently facing a challenge while attempting an automated test on Facebook. The issue lies in clicking the "Create Account" button using FindElement by id, which is not functioning as expected. public void createAccount(String firstName, String lastN ...

Leveraging JavaScript for setting an ASP.net Dropdownlist

I have made several attempts to set the dropdownlist without success. Despite observing the selectedIndex changing appropriately in developer tools, and noticing the selected option node change from false to true, the dropdownlist still displays the first ...

The user is defined, but the user's user ID is not specified

It seems that the user is defined, but user.user_id is not. My framework of choice is express.js and passport.js. router.post('/requestSale', function(req,res){ console.log('session user: ' + req.session.passport.user); //logs ...

Matching stroke-dashoffset in SVG between two distinct paths

I am currently working on animating stroke-dashoffset for two different paths to create a drawing effect. There are buttons provided to adjust the stroke-dashoffset values. My goal is to ensure that the filled paths align vertically as they progress. Is t ...

Disable the button until all input fields contain text in ASP

Curious if anyone knows how to disable a button until all text boxes have input in ASP.NET and C#. Here is an image showing the scenario I'm referring to - wanting to gray out the commit button. Thanks, Chris! ...

Sending data to and retrieving data from a server

Just a quick query. I've been using ajax POST and GET methods to send JSON data to a server and then fetch it back. However, I'm facing some confusion while trying to extract JSON information from the GET call. getMessage = function(){ $.ajax ...

Learn how to dynamically show the chosen option from a dropdown menu in input text fields using AngularJS

html file: <select ng-model="shipping" ng-options="shipping.shipping for shipping in shipAddress"> <option value=''>--Select Address --</option> </select> <form name="shippingForm" class="form-horizontal" role="form" ...

What is the method for formatting within the <textarea> element?

While working on developing a comment system, I recently made the discovery that text areas cannot be formatted to retain paragraphs, line breaks, etc. This was particularly noticeable when comparing sites like StackOverflow, which uses a text editor inste ...

Django: Is there a way to modify the PayPal script for pay upon arrival?

I currently do not wish to accept online payments on my e-commerce site. Instead, I would like the courier to handle package delivery and collection of fees. How can I modify the PayPal script to bypass validations and only register payments upon arrival? ...

Clearing Time Field Input in Safari

Recently, I've been utilizing the following HTML input element: <input type="time"> While testing it in both Chrome and Safari, I noticed that the clear field (cross button) is absent when using Safari. How can I make the cross button appear i ...

Using Firestore startAt() with Redux: a comparison of serializable and non-serializable scenarios

I find myself at a pivotal moment in my Firebase project and am seeking some general guidance. Here are the key points as I have gathered them through my research: When it comes to Firestore queries, there is a useful feature for pagination called startAt ...

Tips for choosing a loaded element using the jQuery load() method

I am currently facing a challenge with the following (here is a snippet of code to illustrate): <div id="container"></div> <script type="text/javascript"> $('#container').load('content.html'); $('.eleme ...