2017-03-08 30 views
0

然而,随着新项目的另一个令人不安的情况:控制器在AngularJS不承认1.5.7

继控制器代码:

(function() { 
'use strict'; 

angular 
    .module('offerRequest', []) 
    .controller('offerRequestCtrl', offerRequestCtrl); 

offerRequestCtrl.$inject = ['$scope', '$rootScope', '$location']; 

function offerRequestCtrl($scope, $rootScope, $location) { 
    // controller code starts here. 

    /* jshint validthis:true */ 
    var vm = this; 
    vm.title = 'offerRequestCtrl'; 

    activate(); 

    function activate() { } 
} 
})(); 

用下面的路由:

// state for requesting offers 
    .state('offerrequest', { 
     url: '/offerrequest', 
     templateUrl: 'app/components/offerrequest/offerrequest.html', 
     controller: 'offerRequestCtrl' 
    }) 

导致以下错误消息:

Argument 'offerRequestCtrl' is not a function, got undefined 

试图定义它的旧式:

angular.module('offerRequest', []) 
    .controller('offerRequestCtrl', function offerRequestCtrl() { 

    }); 

抛出了同样的错误。在我想与之合作的第一个实施中,我可能会做错什么?

+2

你用过'.module( 'offerRequest',[])'某处其他? – Satpal

+0

你能提供一个plunkr或jsfiddle吗? – vjarysta

+0

@satpal是的,我正在使用另一项服务。那是不正确的方式?我删除了服务,它仍然抛出相同的错误。 – poptard

回答

2

你需要有依赖性声明的唯一的全球模块,

angular 
    .module('offerRequest', []) 

更改您的控制器,

angular 
    .module('offerRequest') 
    .controller('offerRequestCtrl', offerRequestCtrl); 
+0

我从服务中删除了依赖关系,但不是控制器,现在它可以工作。谢谢您的帮助。 – poptard

+0

我不能接受新的答案,直到4分钟。对不起,我会在那之后。 – poptard

+0

@Satpal其传统让我们提醒别人接受答案;) –