Rectangle 27 26

I had the same error message (in my case : "Argument 'languageSelectorCtrl' is not a function, got undefined").

After some tedious comparison with Angular seed's code, I found out that I had previously removed a reference to the controllers module in app.js. (spot it at https://github.com/angular/angular-seed/blob/master/app/js/app.js)

And when I added the missing reference:

angular.module('MyApp', ['MyApp.filters', 'MyApp.services', 'MyApp.controllers', 'MyApp.directives'])

The error message disappeared and Angular could instanciate the controllers again.

had the same problem, my issue was that I forgot to add my controller to the app module... why does this not happen automatically??? thanks anyhow!

angularjs - Error: Argument is not a function, got undefined - Stack O...

angularjs playframework
Rectangle 27 2

If you are in a submodule, don't forget to declare the module in main app. ie :

<scrip>
angular.module('mainApp', ['subModule1', 'subModule2']);

angular.module('subModule1')
   .controller('MyController', ['$scope', function($scope) {
      $scope.moduleName = 'subModule1';
   }]);
</script>
...
<div ng-app="mainApp">
   <div ng-controller="MyController">
   <span ng-bind="moduleName"></span>
</div>

If you don't declare subModule1 in mainApp, you will got a "[ng:areq] Argument "MyController" is not a function, got undefined.

angularjs - Error: Argument is not a function, got undefined - Stack O...

angularjs playframework
Rectangle 27 1

I had the same error with a big mistake:

You see ? i forgot the '' around the first $scope, the right syntax is of course:

appFormid.controller('TreeEditStepControlsCtrl', ['$scope', function($scope){

}]);

angularjs - Error: Argument is not a function, got undefined - Stack O...

angularjs playframework
Rectangle 27 9

Although not directly related to the context of this question, this error message can also be caused by a resolve block returning something else than a function, like this:

$stateProvider.state('mystate', {
    url: "/myurl",
    templateUrl: "mytemplate.html",
    controller: "MyController",
    resolve: {
        authenticatedUser: securityAuthorizationProvider.requireAuthenticatedUser
    }
});
securityAuthorizationProvider.requireAuthenticatedUser

angularjs [ng:areq] Argument 'fn' is not a function, got string - Stac...

angularjs
Rectangle 27 9

Although not directly related to the context of this question, this error message can also be caused by a resolve block returning something else than a function, like this:

$stateProvider.state('mystate', {
    url: "/myurl",
    templateUrl: "mytemplate.html",
    controller: "MyController",
    resolve: {
        authenticatedUser: securityAuthorizationProvider.requireAuthenticatedUser
    }
});
securityAuthorizationProvider.requireAuthenticatedUser

angularjs [ng:areq] Argument 'fn' is not a function, got string - Stac...

angularjs
Rectangle 27 168

With Angular 1.3+ you can no longer use global controller declaration on the global scope (Without explicit registration). You would need to register the controller using module.controller syntax.

angular.module('app', [])
    .controller('ContactController', ['$scope', function ContactController($scope) {
        $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"];

        $scope.add = function() {
            $scope.contacts.push($scope.newcontact);
            $scope.newcontact = "";

        };
    }]);
function ContactController($scope) {
    $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"];

    $scope.add = function() {
        $scope.contacts.push($scope.newcontact);
        $scope.newcontact = "";
    };
}
ContactController.$inject = ['$scope'];
angular.module('app', []).controller('ContactController', ContactController);
allowGlobals
angular.module('app')
    .config(['$controllerProvider', function($controllerProvider) {
        $controllerProvider.allowGlobals();
    }]);

Here is the comment from Angular source:-

  • check if a controller with given name is registered via $controllerProvider
  • check if evaluating the string on the current scope returns a constructor
  • if $controllerProvider#allowGlobals, check window[constructor] on the global window object (not recommended)
.....

expression = controllers.hasOwnProperty(constructor)
            ? controllers[constructor]
            : getter(locals.$scope, constructor, true) ||
                (globals ? getter($window, constructor, true) : undefined);

How to check this as suggested? check if a controller with given name is registered via $controllerProvider

javascript - Controller not a function, got undefined, while defining ...

javascript angularjs angularjs-directive angularjs-scope
Rectangle 27 168

With Angular 1.3+ you can no longer use global controller declaration on the global scope (Without explicit registration). You would need to register the controller using module.controller syntax.

angular.module('app', [])
    .controller('ContactController', ['$scope', function ContactController($scope) {
        $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"];

        $scope.add = function() {
            $scope.contacts.push($scope.newcontact);
            $scope.newcontact = "";

        };
    }]);
function ContactController($scope) {
    $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"];

    $scope.add = function() {
        $scope.contacts.push($scope.newcontact);
        $scope.newcontact = "";
    };
}
ContactController.$inject = ['$scope'];
angular.module('app', []).controller('ContactController', ContactController);
allowGlobals
angular.module('app')
    .config(['$controllerProvider', function($controllerProvider) {
        $controllerProvider.allowGlobals();
    }]);

Here is the comment from Angular source:-

  • check if a controller with given name is registered via $controllerProvider
  • check if evaluating the string on the current scope returns a constructor
  • if $controllerProvider#allowGlobals, check window[constructor] on the global window object (not recommended)
.....

expression = controllers.hasOwnProperty(constructor)
            ? controllers[constructor]
            : getter(locals.$scope, constructor, true) ||
                (globals ? getter($window, constructor, true) : undefined);

How to check this as suggested? check if a controller with given name is registered via $controllerProvider

javascript - Controller not a function, got undefined, while defining ...

javascript angularjs angularjs-directive angularjs-scope
Rectangle 27 1

Really great advise, except that the SAME error CAN occur simply by missing the critical script include on your root page

np-app="saleApp"
<script src="./ordersController.js"></script>
.when('/orders/:customerId', {
     controller: 'OrdersController',
     templateUrl: 'views/orders.html'
 })

So essential the undefined controller issue CAN occur in this accidental mistake of not even referencing the controller!

javascript - Controller not a function, got undefined, while defining ...

javascript angularjs angularjs-directive angularjs-scope
Rectangle 27 8

The problem is that the function uses path expressions like item which need a context item as the specification mandates "Within the body of a stylesheet function, the focus is initially undefined; this means that any attempt to reference the context item, context position, or context size is a non-recoverable dynamic error. [XPDY0002]". So the function needs to have a parameter that passes in the node or sequence of nodes to which the path should be applied e.g.

<xsl:function name="sps:GoogleChartDataSourceUnitCount" as="xs:string">
  <xsl:param name="nodes"/>
  <xsl:sequence select="concat(string-join($nodes/item/string(...)))"/>
</xsl:function>
sps:GoogleChartDataSourceUnitCount(.)

If the stylesheet is generated by some tool from Altova you might want to enquire in the Altova forums whether this is a known issue and whether a fix is available.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

XSLT 2.0 produces error: "the context item is undefined" - Stack Overf...

xslt xslt-2.0 saxon altova
Rectangle 27 3

undefined is not a function means redirect is not a function (or method) of res. I'll bet you if you do console.log(res), you won't get an error, which means that, yes, res is defined, but redirect is not. It is an ExpressJS method, so I assume you haven't require'ed Express is your app, if you were planning to use it.

response.writeHead(302, {
  'Location': 'your/404/path.html'
  //add other headers here...
});
response.end();

The HTTP response status code 302 Found is a common way of performing URL redirection.

Thanks josh I use the following library,github.com/nodejitsu/node-http-proxy how should I use it here ?

@Mark, you're welcome. Same exact way as I just explained it... The library is irrelevant. There is no redirect method in your library, so you're out of luck. The example I've provided above shows a way to redirect.

@Mark, I edited my answer, see hostRewrite in the library. That's one way. However, I'm not sure where you got redirect from, as nowhere in that library's API does it mention any redirect method.

Thanks Josh Did you see my updated post I put the libarary which I use and which logic there,how should I use it with your suggestion (the host rewrite ?I just want that the url redirect the application to the new port of the new server that created....can you assist please?

@Mark, I would recommend just reading through the API, I've never used it before.

javascript - error function is not defined for res node - Stack Overfl...

javascript node.js
Rectangle 27 28

You get this error when the function isn't on the MATLAB path or in pwd.

First, make sure that you are able to find the function using:

>> which divrat
c:\work\divrat\divrat.m
>> which divrat
'divrat' not found.

It is not on the MATLAB path or in PWD.

Second, make sure that the directory that contains divrat is on the MATLAB path using the PATH command. It may be that a directory that you thought was on the path isn't actually on the path.

Finally, make sure you aren't using a "private" directory. If divrat is in a directory named private, it will be accessible by functions in the parent directory, but not from the MATLAB command line:

>> foo

ans =

     1

>> divrat(1,1)
??? Undefined function or method 'divrat' for input arguments of type 'double'.

>> which -all divrat
c:\work\divrat\private\divrat.m  % Private to divrat

MATLAB error: Undefined function or method X for input arguments of ty...

function matlab
Rectangle 27 1

As it stands, what you're trying to do is to pass a parameter to jQuery's click function. More specifically, the return value of your call to bind, which just returns a jQuery object, which is not a function, hence apply is undefined on it and this results in the error that you're getting.

You need to wrap what you wrote inside click() in a function declaration:

$("#sortHeader").click( function(e) { //important!

$(".tablesorter")
.bind("sortStart",function(e, table) 
    {
        $('.tablesorter').trigger('pageSet',0);

    })

}); //close it too

tablesorter - "e.handler.apply" is not a function in jquery table sort...

jquery tablesorter
Rectangle 27 2

I got a lot of these errors just now. What happened is that I split a header-file-only class into a header file and a cpp file. However, I didn't update my build system, so the cpp file didn't get compiled. Among simply having undefined references to the functions declared in the header but not implemented, I got a lot of these typeinfo errors.

The solution was to re-run the build system to compile and link the new cpp file.

c++ - g++ undefined reference to typeinfo - Stack Overflow

c++ linker g++
Rectangle 27 6

I had this problem recently with the jQuery Validation plug-in, using Squishit, also getting the js error:

"undefined is not a function"

I fixed it by changing the reference to the unminified jquery.validate.js file, rather than jquery.validate.min.js.

@MvcHtmlString.Create(
    @SquishIt.Framework.Bundle.JavaScript()
        .Add("~/Scripts/Libraries/jquery-1.8.2.min.js")
        .Add("~/Scripts/Libraries/jquery-ui-1.9.1.custom.min.js")
        .Add("~/Scripts/Libraries/jquery.unobtrusive-ajax.min.js")
        .Add("~/Scripts/Libraries/jquery.validate.js")
        .Add("~/Scripts/Libraries/jquery.validate.unobtrusive.js")
         ... more files

I think that the minified version of certain files, when further compressed using Squishit, for example, might in some cases not deal with missing semi-colons and the like, as @Dustin suggests, so you might have to experiment with which files you can doubly compress, and which you just leave to Squishit or whatever you're bundling with.

Using the unminified version was just the ticket for me - thanks.

For me it was the json2.min.js file from version 1.0.2 of a NuGet package which was causing the problem. I switched it to the non-min file and the Squishit combined file works fine now.

javascript - Uncaught TypeError: undefined is not a function on loadin...

javascript jquery minify
Rectangle 27 3

Solaris 10's /usr/bin/awk doesn't have a system function, and it will not raise an error when you make a call to an undefined function; the return value of the function will be whatever its argument is. Instead, use either /usr/xpg4/bin/awk or nawk.

As Glenn and Andrew pointed out, if all you need to do is run a shell command multiple times with one argument varying each time, this can be done in the shell itself without getting awk involved.

for f in *.dmp
do
    nohup scp "$f" username@server:/server/file/path/ &
done

bash - need assistance with awk using system in Solaris - Stack Overfl...

bash shell unix awk solaris
Rectangle 27 2

I had a case where I'm pretty sure that my code would run smoothly. But still, got an error and I checked the Javascript console of Google Chrome to check what it is.

opt.SetAttribute("value",values[a]);

And got the same error message:

Uncaught TypeError: undefined is not a function

Nothing seems wrong with the code above but it was not running. I troubleshoot for almost an hour and then compared it with my other running code. My error is that it was set to SetAttribute, which should be setAttribute.

javascript - Uncaught TypeError: undefined is not a function on loadin...

javascript jquery minify
Rectangle 27 7

JavaScript isn't very picky when it comes to the number of required function arguments when you call a function; any arguments that are mentioned in the declaration but not passed will be set to the type undefined.

undefined
'default value'

Lastly, you can count the number of arguments that were passed:

function test(foo)
{
    console.log(arguments.length > 0 ? foo : 'default value');
}
foo

Although undefined is not writeable since ES5, not all browsers will be so vigilant to enforce this. There are two alternatives you could use if you're worried about this:

foo === void 0;
typeof foo === 'undefined'; // also works for undeclared variables

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

How to set a variable passed on to a function as null in JavaScript - ...

javascript
Rectangle 27 7

JavaScript isn't very picky when it comes to the number of required function arguments when you call a function; any arguments that are mentioned in the declaration but not passed will be set to the type undefined.

undefined
'default value'

Lastly, you can count the number of arguments that were passed:

function test(foo)
{
    console.log(arguments.length > 0 ? foo : 'default value');
}
foo

Although undefined is not writeable since ES5, not all browsers will be so vigilant to enforce this. There are two alternatives you could use if you're worried about this:

foo === void 0;
typeof foo === 'undefined'; // also works for undeclared variables

How to set a variable passed on to a function as null in JavaScript - ...

javascript
Rectangle 27 1

{{::vm.action}} is a reference to the function vm.action while {{::vm.action()}} executes that function when the template is rendered. Angular is binding the return value of that function (undefined in this case) to your ng-click. Just get rid of the Angular expression delimiters in the click handler:

<article>
    <h1>{{::vm.title}}</h1>
    <p>{{::vm.body}}</p>
    <button ng-click="vm.action()">{{::vm.button}}</button>
</article>

angularjs - How do you fire a button click that does different things ...

angularjs angularjs-directive angularjs-scope angularjs-ng-click
Rectangle 27 7

This is a really valid case. Especially because foo could be a function from the STL like std::count which takes a const T& as its third argument.

I spent much time trying to understand why the linker had problems with such a basic code.

tells us that the linker cannot find a symbol.

$nm -C main.o
0000000000000000 T main
0000000000000000 W void foo<int>(int const&)
0000000000000000 W Bar::func()
0000000000000000 U Bar::kConst

We can see from the 'U' that Bar::kConst is undefined. Hence, when the linker tries to do its job, it has to find the symbol. But you only declare kConst and don't define it.

The solution in C++ is also to define it as follows:

template <typename T>
void foo(const T & a) { /* code */ }

class Bar
{
public:
   static const int kConst = 1;
   void func()
   {
      foo(kConst);           // This is the important line
   }
};

const int Bar::kConst;       // Definition <--FIX

int main()
{
   Bar b;
   b.func();
}

Then, you can see that the compiler will put the definition in the generated object file:

$nm -C main.o
0000000000000000 T main
0000000000000000 W void foo<int>(int const&)
0000000000000000 W Bar::func()
0000000000000000 R Bar::kConst

Now, you can see the 'R' saying that it is defined in the data section.

Is it OK that a constant appears in "nm -C" output twice, first with an "R" and an address, and then with an "U"?

>nm -C main.o | grep kConst
0000000000400644 R Bar::kConst

In this case, of course ! A static library is only an aggregate of object files. The linkage is only done by the client of the static lib. So if you put in the archive file, the object file containing the definition of the const and another object file calling Bar::func(), you will see the symbol once with the definition and once without: nm -C lib.a gives you Constants.o: 0000000000000000 R Bar::kConst and main_file.o: U Bar::kConst ....

c++ - Undefined reference to static const int - Stack Overflow

c++ gcc