0

I'm working on Salesforce Visualforce template and components, I have the below code embedded and I'm trying to fix the bug.

I did check the similar link here : AngularJS error: [ng:areq] Argument 'TestController' is not a function, got undefined

<div xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ng-app="vsTestApp">
...
    <c:TestController />
    <c:TestTemplate />
...
</div>

The code for TestController

<apex:component >
<script>
(function() {
    'use strict';
    angular
    .module('vsTestApp', []);
}());

(function() {
    'use strict';
    angular
    .module('vsTestApp')
    .controller('testController', testController);

    testController.$inject = ['$filter', '$window' ,'$rootScope' ];

    function testController($filter, $window , $rootScope) {
        //Some Logic's Here
        function print() {
            $window.print();
        }
    }
}());
</script>
</apex:component>

The code for TestTemplate

<apex:component >
<script type="text/ng-template" id="vlcCompareModal.html">
    <a clasS="btn btn-default" ng-controller="testController as smallGroup"  ng-click="smallGroup.print()">Print</a>
</script>  
</apex:component>

I'm getting error saying Argument 'testController' is not a Link : https://docs.angularjs.org/error/ng/areq?p0=testController&p1=not%20a

5
  • Updated. I believe still the error exists. Thanks for the info. Commented Mar 21, 2017 at 18:12
  • @Aman what do you mean by that using that only will give you faster results? Commented Mar 21, 2017 at 18:15
  • Yes @Aman, still the error exists. Commented Mar 21, 2017 at 18:20
  • where have you read that? I have never heard such thing Commented Mar 21, 2017 at 18:20
  • @DeepakBandi I think you need to define your controller after $injecting dependencies. Like testController.$inject = ['$filter', '$window' ,'$rootScope' ]; and then app.controller('testController', testController) Commented Mar 21, 2017 at 18:24

3 Answers 3

1

Try defining your controller after the controller function:

(function() {
    'use strict';

     testController.$inject = ['$filter', '$window' ,'$rootScope'];

     function testController($filter, $window , $rootScope) {
         //Some Logic's Here
         function print() {
            $window.print();
         }
     }

     angular.module('vsTestApp')
         .controller('testController', testController);
}());
Sign up to request clarification or add additional context in comments.

1 Comment

since he's defining the controller as named function (and not using var testController = function(){..}) this isn't the problem
0

This is off topic but that is a mess.

Why would you simply not do:

.controller('testcontroller', ['$filter', $window', '$rootscope', function($filter, $windwo, $rootscope) {

}]);

Much more concise and easier to read and understand for others looking at your code.

2 Comments

Its a code which is already written and I'm trying to fix it.
looks like somebody munged the typescript way of doing things and the vanilla way.
0

Shouldn't it be <c:testController /> instead of <c:TestController /> ?

1 Comment

It is the way filename is saved and the file name is TestController.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.