Skip to content Skip to sidebar Skip to footer

Angular Js & Typescript - Error: Ng:areq Bad Argument "argument 'xxxxxx' Is Not A Function, Got Undefined"

Keep getting an error specified in the title. I split models and controllers into separate files stored under models and controllers directories respectively. When I tried to link

Solution 1:

So, we had some progress with the other answer. But now new issues appeared and OP created this plunker

http://plnkr.co/edit/WLH1GgLlpE7nek1poWnA?p=preview

With this error message:

TypeError: rightpane.RightPaneTabList is not a function at new RightPaneCtrl (RightPaneCtrl.js:14) ...

There is updated and partially working version. The problem was ... missing components loaded into the browser... When we create documents like this

enums/ECategoryType.js models/Item.js models/Tab.js models/RightPaneTabList.js controllers/RightPaneCtrl.js Application.js

We have to append all of them (and in correct order) into the page code:

<scriptsrc="enums/ECategoryType.js"></script><scriptsrc="models/Item.js"></script><scriptsrc="models/Tab.js"></script><scriptsrc="models/RightPaneTabList.js"></script><scriptsrc="controllers/RightPaneCtrl.js"></script><scriptsrc="Application.js"></script>

(there are missing images, but app should start)

Solution 2:

There are two issues. There is a working example, showing the changes below in action (simplified version, just to make it running)

Firtly, if we want to use some class.. it already must be loaded, so we must change order of these scripts

// here we must make JS aware about our Ctrl
<scriptsrc="controllers/RightPaneCtrl.js"></script><scriptsrc="Application.js"></script> 
// here it would be too late
// <scriptsrc="controllers/RightPaneCtrl.js"></script>

And also, becase our Controller has module/namespace:

module rightpane {        
    exportclassRightPaneCtrl {
    ...

We must assign it with its full name:

angular.module('rightpaneMVC')
    // instead of this// .controller('rightPaneCtrl', RightPaneCtrl);// wee need this
    .controller('rightPaneCtrl', rightpane.RightPaneCtrl);

Check it here

Post a Comment for "Angular Js & Typescript - Error: Ng:areq Bad Argument "argument 'xxxxxx' Is Not A Function, Got Undefined""