app.js
.state('publishmsg/new-message', {
url: '/publishmsg/new-message',
templateUrl: 'templates/publish-msg/publishmsg-form.html',
controller: 'publishMessageController'
})
.state('add-tags', {
url: '/add-tags',
templateUrl: 'templates/publish-msg/publishmsg-form-tags.html',
controller: 'publishMessageFormTagController'
})
publishMessageController.js
angular.module("mobApp.controllers",['ionic','ngTagsInput','angular-carousel'])
.controller("publishMessageController",function($scope, $http, $location, $ionicLoading, $cordovaToast, deviceStatus){
$scope.gotoAddTag = function()
{
$location.path('add-tags');
}
publishMessageFormTagController.js
angular.module("mobApp.controllers",['ionic'])
.controller("publishMessageFormTagController",function($scope, $http, $location, $ionicLoading, $cordovaToast, deviceStatus){
index.html
<script src="js/controllers/publishMessageFormTagController.js"></script>
<script src="js/controllers/publishMessageController.js"></script>
现在在publishmsg-form.html
<div class="item formTagList" ng-click='gotoAddTag()' id="publishMsgFormTags">
当我打电话给gotoAddTag()
时,它会抛出
Error: [ng:areq] Argument 'publishMessageFormTagController' is not a function, got undefined
答案 0 :(得分:0)
重新初始化模块,请参阅下面的案例,
<强> publishMessageController.js 强>
angular.module("mobApp.controllers",['ionic','ngTagsInput','angular-carousel'])
<强> publishMessageFormTagController.js 强>
angular.module("mobApp.controllers",['ionic'])
在这里第二个模块声明将覆盖第一个
所以你需要像
这样的东西angular.module("mobApp.controllers").controller("publishMessageFormTagController",function($s....
请注意,此处不存在传递给angular.module()
的第二个数组参数,因此angular将获取您定义的前一个模块,并将控制器publishMessageFormTagController
附加到该模块。如果参数数组存在,则angular将覆盖第一个模块并将publishMessageFormTagController
分配给模块,但由于它覆盖了第一个模块,因此无法找到控制器publishMessageController
。