0

I am a beginner with AngularJs and I am trying to use controller while creating a simple application. However I am getting an Error and I can't quite figure it out

Error: ng:areq Bad Argument. Argument 'languages' is not a function, got undefined

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <title>Angular JS | Controllers</title>
    <script type="text/javascript" src="../resources/js/angular.min.js"></script>

    <script>
        (function(angular){
            var myApp = angular.module('myApp', []);
            myApp.controller = ('languages', function($scope){
                $scope.myFavLanguage = 'None';
            });
        })(window.angular);


    </script>
</head>
<body >

    <div ng-controller="languages">
        Select your favourite langauge:
        <button>ReactJS</button>
        <button>PHP</button>
        <button>JavaScript</button>
        <button>C++</button>

        <p>Your favourite language is {{myFavLanguage}}</p>
    </div>


</body>
</html>

I have searched over the internet and gone through a few questions on stackoverflow and could'nt get any of them to solve my problem. These are the ones that I have visited along with a few others. Kindly visit these before marking it as duplicate because it isn't:

Angularjs bad argument ng:areq error

Angularjs: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined

Argument ... is not a function, got undefined

Thanks for any help

Community
  • 1
  • 1
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400

1 Answers1

3

To define a controller, use the controller() method.

myApp.controller = ('languages', function($scope){
                 ^

Remove the = from this.

myApp.controller('languages', function($scope) {

Check Docs for more information.

I'll suggest you to use min-safe syntax.

myApp.controller('languages', [$scope, function ('$scope') {

}]);
Community
  • 1
  • 1
Tushar
  • 85,780
  • 21
  • 159
  • 179
  • Silly mistake made me search all over the internet, Still couldnt solvet the problem. Thanks. and yeah I was using the min-safe syntax only. Removed it to just to check – Shubham Khatri Jul 13 '16 at 10:17