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

174 Views Asked by At

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!!!

1

There are 1 best solutions below

1
On

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>