Angular JS Error: [$ injector: modulerr]

Edit: Now that I have really worked using angularjs, I do not recommend anyone doing what I was trying to accomplish.

This is my first Angularjs app, so I'm nooby and still trying to figure things out. But I get an error in my Chrome console that says the following:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.0-beta.1/$injector/modulerr?p0=app&p1=Error…s.org%2F1.3.0-beta.1%2F%24injector%2Fnomod%3Fp0%3Dapp%0A%20%20%20%20at%20E...<omitted>...1) angular.min.js?1394393789:6
(anonymous function) angular.min.js?1394393789:6
(anonymous function) angular.min.js?1394393789:30
r angular.min.js?1394393789:7
e angular.min.js?1394393789:29
cc angular.min.js?1394393789:32
c angular.min.js?1394393789:17
bc angular.min.js?1394393789:18
cd angular.min.js?1394393789:17
(anonymous function) angular.min.js?1394393789:208
l jquery-2.0.3.js:2913
c.fireWith jquery-2.0.3.js:3025
x.extend.ready jquery-2.0.3.js:398
S

Which sends me to this page: http://docs.angularjs.org/error/ $ injector / modulerr? p0 = app & p1 = Error:% 20% 5B $ injector: nomod% 5D% 20http:% 2F% 2Ferrors.angularjs.org% 2F1.3.0-beta.1% 2F $ injector% 2Fnomod% 3Fp0% 3Dapp% 0A% 20% 20% 20% 20at% 20E

I can not transfer any application from version 1.2 and below. I followed the documentation for some simple code below.

angular, : http://docs.angularjs.org/tutorial/step_02

{{split.description}}. ?

HTML

<html lang="en" ng-app="app">
    <head>
        <!-- My CSS Here -->
    </head>

    <body>
        <div ng-controller="SplitController">
            <div ng-repeat="split in splits">
                <h4>{{split.description}}</h4>
            </div>
        </div>
    </body>

</html>

JavaScript

var Split = function(data)
{
    this.description = data['description'];
}

function getSplits(parentid) {
    var url = "/transaction/split/get";
    var ajax = $.ajax({
        type: 'GET',
        dataType: 'json',
        url: url,
        data: {
            parentid: parentid
        },
        beforeSend: function(data){
        },
        success: function(data){
            data = JSON.parse(data, true);
            var splits = [];
            for(var i = 0; i < splits.length; i++)
            {
                splits.push(new Split(splits[i]));
                console.log(splits[i]);
            }
            var app = angular.module("app", []);
            app.controller('SplitController', function($scope){
                $scope.splits = splits;
            });
        },
        error: function(data){
            //$('body').html(JSON.stringify(data));
        }
    }).done(function(data){
        });
}

$(document.ready(function(){
    getSplits(1);
});
+4
4

, , angular $ jquery. , , ( script).

success: function(data){
  ... //splits and whatnot
  var $scope = angular.element($("div[ng-controller='SplitController']")).scope()
  $scope.$apply(function(){
    $scope.splits = splits;
  })
}

, , ng-app document.ready. , ng-, . , SplitController, "splits" , ng-repeat "split" DOM .

+2

angular jQuery . angular jQuery . document.ready - angular . , ng-app. , , .

+1

...

ng-app"app"

, , ..

ng-app="app"

, , ajax angular. angular ajax, $http, , , ngRoute

0

Your code is not even close to the one you are talking about. You should not use document.ready and not use $ .ajax, and your controller should be the one making the ajax request, not the result of the ajax request itself.

The code for step 2 is as follows:

var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', function($scope) {
  $scope.phones = [
    {'name': 'Nexus S',
     'snippet': 'Fast just got faster with Nexus S.'},
    {'name': 'Motorola XOOM™ with Wi-Fi',
     'snippet': 'The Next, Next Generation tablet.'},
    {'name': 'MOTOROLA XOOM™',
     'snippet': 'The Next, Next Generation tablet.'}
  ];
});

If you want to use ajax instead, you must enter the service $httpin your controller and use this.

var app = angular.module('app', []);

app.controller('SplitController', function($scope, $http) {
  $http.get( // or post, put, delete
      '/transaction/split/get', 
      {some data}
  ).success(function(returndata) {
    $scope.splits = returndata;
  });
});
0
source

Source: https://habr.com/ru/post/1530862/


All Articles