Shubham Khatri Shubham Khatri - 1 year ago 189
AngularJS Question

AngularJS Error: ng:areq Bad Argument while using controller

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">
<title>Angular JS | Controllers</title>
<script type="text/javascript" src="../resources/js/angular.min.js"></script>

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

<body >

<div ng-controller="languages">
Select your favourite langauge:

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


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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download