我正在使用Salesforce Visualforce模板和组件,嵌入了以下代码,并试图修复该错误。
我在这里检查了类似的链接: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>
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>
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>
我收到错误消息说参数'testController'不是
链接:https://docs.angularjs.org/error/ng/areq?p0=testController&p1=not%20a
最佳答案
尝试在控制器功能之后定义控制器:
(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);
}());