gpt4 book ai didi

javascript - 错误 : [ng:areq] Argument 'addCtrl' is not a function, 未定义

转载 作者:行者123 更新时间:2023-12-02 11:01:13 25 4
gpt4 key购买 nike

我是 AngularJS 的新手,遇到了这个错误,我从所有 Stackoverflow 引用资料中获取了相同错误的帮助,但未能解决我的问题,所以在这里发布。代码工作正常,一旦我集成了 plivo 模块,它就开始出现以下错误。 enter image description here

请帮我解决这个问题,已经浪费了1天。谢谢。

添加Ctrl.js

// Creates the addCtrl Module and Controller. Note that it depends on 'geolocation' and 'gservice' modules.
var addCtrl = angular.module('addCtrl', ['angularModalService']);
addCtrl.controller('addCtrl', function($scope, $http, $rootScope, $location,$routeParams, $q , $timeout , plivoclient, ModalService){

// Initializes Variables
// ----------------------------------------------------------------------------
$scope.formData = {};
$scope.formData.preferredMode = "data";
$scope.formData.emailId = "prateek@teledna.com";
$scope.formData.phone = "+919986040933";

$scope.$on('incoming:call', function(event, data) {
console.log('Instance Id: ' + data.extraHeaders['X-Ph-Instid']);
$timeout(function() {
ModalService.showModal({
templateUrl: 'partials/addForm.html',
controllerAs: 'vm',
controller: 'IncomingCallController',
inputs: {
from: data.callerName || '',
instId: data.extraHeaders['X-Ph-Instid'] || data.extraHeaders['X-Ph-instid']
}
});
}, 0);
});


function activate(){
console.log("activate in addCtrl is called..");
callResolver();
}

activate();

var param1 = $routeParams.param1;
var param2 = $routeParams.param2;

console.log(param1);
console.log(param2);

// submitting new user Details
$scope.submitUserDetails = function() {

var userData = {
emailId: $scope.formData.emailId,
preferredMode: $scope.formData.preferredMode,
phone: $scope.formData.phone,
alternatePhone: $scope.formData.alternatePhone,
};

console.log('in normal add user :'+JSON.stringify(userData));

// Saves the user data to the db
saveUserData(userData);
};


function saveUserData(userData){
$http.post('/users', userData)
.success(function (data) {
$location.path('/submitted');
})
.error(function (data) {
console.log('Error: ' + data);
});
}

function callResolver() {
console.log("call resolver is called..");
var deferred = $q.defer();
var sessionUser= {
"plivo_sip_credentials": {
"username": "N919986040933160719091504",
"password": "now1516confer",
"endpoint_id": "95086867054112",
"sip_uri": "sip:N919986040933160719091504@phone.plivo.com"
}
};
plivoclient.start(sessionUser).then(function() {
console.log("Plivo client connected..");
deferred.resolve();
}, function() {
console.log("Plivo client cannot be connected..");
deferred.reject(4);
});
return deferred.promise;
};

});

app.js
// Declares the initial angular module "NowConfer". Module grabs other controllers and services.
var app = angular.module('nowconfer', ['ngRoute' , 'addCtrl'])

// Configures Angular routing -- showing the relevant view and controller when needed.
.config(function($routeProvider){

// Join Team Control Panel
$routeProvider.when('/join/:param1/:param2', {
controller: 'addCtrl',
templateUrl: 'partials/addForm.html',

// Find Teammates Control Panel
}).
when('/submitted', {
template: '<div>Thankyou for choosing the preferred mode of call.</div>',
// Find Teammates Control Panel
}).otherwise({redirectTo:'/join'})
});

index.html
<!doctype html>
<!-- Declares NowConfer as the starting Angular module -->
<html class="no-js" ng-app="nowconfer">
<head>
<meta charset="utf-8">
<title>NowConfer</title>
<meta name="description" content="NowConfer">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- CSS -->
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css"/>
<link rel="stylesheet" href="style.css"/>

<!-- JS Source -->
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<script src="lib/angular-modal-service.js"></script>
<script type="text/javascript" src="https://s3.amazonaws.com/plivosdk/web/beta-rc2/plivo.min.js"></script>

<!-- Angular Files -->


<script src="js/app.js"></script>
<script src="js/plivoservice.js"></script>
<script src="js/addCtrl.js"></script>
<script src="js/inject-plivo-directive.js"></script>
<script src="js/incoming.controller.js"></script>
<script src="js/callresolver.js"></script>


</head>

<body>
<div class="container">
<!-- Header Menu. Note use of headerCtrl -->
<div class="header" ng-controller="addCtrl">

<!-- Header items are made active upon selection -->
<ul class="nav nav-pills pull-right">
<li ><a href="/#/join">Prateek</a></li>
</ul>

<!-- Header Title -->
<h3 class="text-muted"><img src="images/l_nowconfer_logo.png" alt="NowConfer" /></h3>
</div>

<!-- Map and Side Panel -->
<div class="row content">

<div ng-view></div>

</div>
<hr/>

<!-- Footer -->
<div class="footer">
<p class="text-center"><span class="glyphicon glyphicon-check"></span> Design & developed by <a href="#">ComVerg Technologies Pvt. Ltd.</a></p>
</div>

</div>

</body>
</html>

传入.controller.js
(function () {
'use strict';

angular
.module('nowconfer',['ngRoute'])
.controller('IncomingCallController', IncomingCallController);

IncomingCallController.$inject = ['$rootScope','plivoclient','$routeProvider','$location'];

function IncomingCallController($rootScope , plivoclient,$routeProvider ,$location) {
var vm = this;
vm.from = from;
vm.connecting = false;

vm.accept = function() {
plivoclient.conn.answer();
vm.connecting = true;
console.log("incoming call accept");
};

vm.hangUp = function() {
plivoclient.conn.reject();
console.log("incoming call hangedup");
};

$rootScope.$on('incoming:call:answered', function() {
console.log("incoming call answered");
$location.path('/join/1/2');
});

$rootScope.$on('incoming:call:cancelled', function() {
console.log("incoming call cancelled");
});
}

}());

callresolver.js
(function () {

'use strict';

angular
.module('nowconfer')
.factory('callResolver', callResolver);

callResolver.$inject = ['$q','plivoclient'];

function callResolver($q, plivoclient) {
var deferred = $q.defer();
var sessionUser= {
"plivo_sip_credentials": {
"username": "N919986040933160719091504",
"password": "now1516confer",
"endpoint_id": "95086867054112",
"sip_uri": "sip:N919986040933160719091504@phone.plivo.com"
}
};
plivoclient.start(sessionUser);
deferred.resolve();
return deferred.promise;
};

})();

最佳答案

尝试从 addCtrl 重命名模块名称至addCtrlModule或者其他的东西。我认为模块名称与 Controller 名称冲突。

只需尝试更改 addCtrl.js 中的这行代码即可跟随。

var addCtrl = angular.module('addCtrlModule', ['angularModalService']);

app.js
var app = angular.module('nowconfer', ['ngRoute' , 'addCtrlModule'])

希望能帮助到你。

关于javascript - 错误 : [ng:areq] Argument 'addCtrl' is not a function, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39567529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com