如何在angularJS的同一视图中使用两个控制器

时间:2015-03-27 05:29:42

标签: angularjs html5

我买了一个模板,它的所有控制器,路由和指令都在一个文件app.js中,这是我的第一个angularJS应用程序, 我已经定义了两个控制器,我想在同一个视图中使用它们,第一个是MailNewCtrl1控制器,它将处理我的表单中的邮件发送选项,第二个是FileUploadCtrl1,它处理附件,我的问题是我有这个错误控制台:



Error: [$injector:unpr] Unknown provider: FileUploaderProvider <- FileUploader
http://errors.angularjs.org/1.3.2/$injector/unpr?p0=FileUploaderProvider%20%3C-%20FileUploader
    at REGEX_STRING_REGEXP (http://localhost/ProjetWeb/src/vendor/angular/angular.js:80:12)
    at http://localhost/ProjetWeb/src/vendor/angular/angular.js:3930:19
    at Object.getService [as get] (http://localhost/ProjetWeb/src/vendor/angular/angular.js:4077:39)
    at http://localhost/ProjetWeb/src/vendor/angular/angular.js:3935:45
    at getService (http://localhost/ProjetWeb/src/vendor/angular/angular.js:4077:39)
    at Object.invoke (http://localhost/ProjetWeb/src/vendor/angular/angular.js:4109:13)
    at $get.extend.instance (http://localhost/ProjetWeb/src/vendor/angular/angular.js:8356:21)
    at http://localhost/ProjetWeb/src/vendor/angular/angular.js:7608:13
    at forEach (http://localhost/ProjetWeb/src/vendor/angular/angular.js:347:20)
    at nodeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:7607:11) <div ui-view="" class="ng-scope">
&#13;
&#13;
&#13;

这就是我使用两个控制器的方式:

&#13;
&#13;
<div ng-controller="MailNewCtrl1">
.........contact form(email,subject,message).........
<div class="form-group" ng-controller="FileUploadCtrl1"  nv-file-drop="" uploader="uploader" filters="queueLimit, customFilter" >......<!--table of attachements!-->
.............</div>
</div>
&#13;
&#13;
&#13;

我在其中定义控制器的app.js:

&#13;
&#13;
'use strict';
angular.module('app', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
])
.controller('FileUploadCtrl1', ['$scope', 'FileUploader', function($scope, FileUploader) {
    var uploader = $scope.uploader = new FileUploader({
        url: 'upload.php'
    });

    // FILTERS

    uploader.filters.push({
        name: 'customFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            return this.queue.length < 10;
        }
    });
.....//the code is too long,this the controller in which I have problem
&#13;
&#13;
&#13; 谢谢你的帮助

3 个答案:

答案 0 :(得分:0)

您正在尝试注入FileUploader服务,但似乎没有在app模块中定义该服务,也不依赖于可能为您提供该服务的其他模块。< / p>

你需要做一个或另一个。

答案 1 :(得分:0)

我猜测FileUploader是在另一个模块中提供的。确保您的模块在该模块上 dependend

angular.module('app', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'FileUploader' // Name of the module goes here
])

答案 2 :(得分:0)

var items = angular.module('items', []);
var text = angular.module('text', []);

text.controller('TextController', function ($scope) {
    //Controller Code Here
});

items.controller('ItemController', function ($scope) {
    //Controller Code Here
});