当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to set a controller file from a subfolder within a route file?

问题描述:

I'm working on a ionic project. I have the following app structure...

app

|__dashboard

|__dashboard.html

|__dashboard.module.js

|__controller.js

|__app.js

|__config.js

index.html

I have a controller defined inside the controller.js. That is:

angular.module('dashboard').controller('Ctrl', function(){

console.log('hello');

});

And I have a route in my app.js. That is:

.

.

.

$stateProvider

.state('app', {

url: 'app/',

abstract: true

})

.state('app.home', {

url: '/home',

views: {

'menuContent': {

templateUrl: 'app/dashboard/dashboard.html',

controller: 'Ctrl'

}

}

});

In my index.html I call all the files:

However, when I run the app, I get the following error:

Error: [ng:areq] Argument 'Ctrl' is not a function, got undefined

Someone can help me please? Thanks!!!

网友答案:

You need to include controller.js script file in your index.html so that you can make use of that controller in routing. Include your controller as:

<script src="/app/dashboard/controller.js"></script>
分享给朋友:
您可能感兴趣的文章:
随机阅读: