You must register the controller in the angular myApp module.
App.js
var myApp = angular.module('myApp', []); myApp.controller('MainController', MainController ); var MainController = function($scope){ $scope.val = "Main controller variable value" }
Basically, what you were doing is correct, but this code was followed by an obsolete version of AngularJS. As you stated, your controller is nothing more than an As controller function, which requires the allowGlobals() method of $controllerProvider . Since the angular 1.3 + allowGlobals() method is disabled by adding the code below, you can enable it to make your code work, but it is not recommended to do this.
Config
myApp.config(['$controllerProvider', function($controllerProvider) { $controllerProvider.allowGlobals(); } ]);
Refer to SO> here
source share