Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: app.all is not a function

I have a very simple angular page here

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

  <p>Today's welcome message is:</p>
  <h1>{{myData}}</h1>

</div>

<script>

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

  app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];

  }

  ]);


  // Added all header request and response.
  app.all('/*', function (request, response, next) {
    response.header("Access-Control-Allow-Origin", "*");
    response.header("Access-Control-Allow-Headers", "X-Requested-With");
    response.header("Access-Control-Allow-Methods", "GET, POST", "PUT", "DELETE");
    next();
  });



  app.controller('myCtrl', function($scope, $http) {
    $http.get("welcome.htm")
    .then(function(response) {
        $scope.myWelcome = response.data;
    });
});


</script>

I kept getting this in my console.

Uncaught TypeError: app.all is not a function

How do I prevent that ?

I'm following this :

https://stackoverflow.com/a/21455819/4480164

like image 313
code-8 Avatar asked Apr 22 '26 01:04

code-8


1 Answers

Just pointing this out because I cannot comment due to low rep, but you are also calling ng-app="myApp" which is looking for a module call for myApp and you do not have a module call for myApp so your controller will not fire correctly either maybe re-word your myApp to app?

like image 91
McMintz Avatar answered Apr 23 '26 14:04

McMintz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!