0

Hi all I would like to read a json file with angular but I am not able too and I get the flowing error

 Error: [ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?
p0=jsonCtrl&p1=not%20a%20function%2C%20got%20undefined

 (anonymous) @ angular.js:12330
(anonymous) @ angular.js:9109
$apply @ angular.js:15947
(anonymous) @ angular.js:1633
 e @ angular.js:4450
d @ angular.js:1631
Ac @ angular.js:1651
Zd @ angular.js:1545
 (anonymous) @ angular.js:28359
  a @ angular.js:2996
 c @ angular.js:3271

My code is index.html is

 <!DOCTYPE html>
 <html ng-app="myApp">

 <head>
  <title>Angular Quickstart</title>
  <base href="/">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Polyfills -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script 

src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js">
</script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
    System.import('main.js').catch(function(err) {
        console.error(err);
    });
 </script>
 <script type="text/javascript">
     var myApp = angular.module('myApp', []);
     myApp.controller('myController', function($scope, $http) {
         $http.get('data.json').success(function(response) {
            $scope.myData = response;
         });
     });
   </script>

   </head>

    <body ng-controller="myController">
     Search : <input type="text" value="" ng-model="search" />
     <table border=1>
         <tr ng-repeat="data in myData | filter : search">
         <td>{{data.Name}}</td>
         <td>{{data.Company}}</td>
           <td><a href="" ng-click="removeName(data)">Remove</a></td>
        </tr>
        </table>
       <div ng-controller="jsonCtrl">

        <my-app>Loading AppComponent content here ...</my-app>
    </body>

  </html>

I have looked a lot but I cannot figure it out. Does this script have to be in different file? or is it good in index.html?I am really new to angular and I have no clue how to approach this problem

2
  • This code is angularjs not angular 2. The syntax is very different and you can see in the version number of your src: 1.4.3. Commented Aug 5, 2017 at 23:01
  • @Amir i have created codepen with online api and it works fine and the error you are getting becuase you didnt create any controller jsonCtrl Commented Aug 6, 2017 at 4:03

1 Answer 1

1

You are using both angularJs and angular 2!, the error you are getting is because of this line

<div ng-controller="jsonCtrl">

There is no controller with name jsonCtrl

But as I said you are using AngularJs and Angular2!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.