2014-02-19 51 views
1

我使用Yeoman在Angular中構建一個練習應用程序。我試圖將我的控制器保存在單獨的文件中。與Yeoman一起使用多個角度控制器

但是,要我的「註冊」的路線時,它拋出在Chrome瀏覽器開發工具的錯誤:

"Error: [ng:areq] Argument 'RegisterCtrl' is not a function, got undefined http://errors.angularjs.org/1.2.6/ng/areq?p0=RegisterCtrl&p1=not%20aNaNunction%2C%20got%20undefined"

儘管它會引發錯誤,但我仍然可以訪問註冊頁面並查看「hello world」內容。

我看:

但無論是幫助解決我的問題,儘管嘗試一些自己的建議。

目前,我的應用程序佈局爲:

app 
... 
--scripts 
---controllers 
-----main.js 
-----register.js 
---app.js 
... 

當我移動register.js的內容轉換成Main.js,它不再拋出一個錯誤。

App.js看起來像這樣:

angular.module('angYeomanApp', [ 
'ngCookies', 
'ngResource', 
'ngSanitize', 
'ngRoute', 
'ui.bootstrap' 
]) 
    .config(function ($routeProvider) { 
    $routeProvider 
     .when('/', { 
     templateUrl: 'views/main.html', 
     controller: 'MainCtrl' 
     }) 
     .when('/register', { 
     templateUrl: 'views/register.html', 
     controller: 'RegisterCtrl' 
     }) 
     .otherwise({ 
     redirectTo: '/' 
     }); 
    }); 

Main.js:

angular.module('angYeomanApp') 
    .controller('MainCtrl', function ($scope) { 

}); 

Register.js:

angular.module('angYeomanApp') 
    .controller("RegisterCtrl", function ($scope) { 

}); 

任何幫助將不勝感激!

回答

7

是從index.html引用的register.js嗎?

+0

解決了它,謝謝! –