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

1
  • @Rakeschand: I included the same link in my question if you notice. and I mentioned that it did not solve my problem. Commented Jul 13, 2016 at 10:20

1 Answer 1

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') {

}]);
Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.