Ramanaa Gj Ramanaa Gj - 1 year ago 83
AngularJS Question

way to provide a path to controller file using ui-router

is there any way to provide a path to a controller file by using UI-ROUTER

this is my code

var kraveln = angular.module('kraveln', ['ui.router' , 'ngMessages' , 'ngDialog' ]);

kraveln.config(function($stateProvider, $urlRouterProvider) {


// for home_page
.state('home', {
url: '/home',// if home page means
views: {
templateUrl: 'app/views/home_search_page.html',
controller: 'app/views/sample_controller.js' // sample controller for loading file.
templateUrl: 'app/views/header_one.html' //load first header
templateUrl: 'app/views/footer.html' //load second footer

as like the template url can we load controller URL i tried but can't able to do so

Answer Source

Yes you can give a specific controller to every view in a state.

          url: '/home',
          views: {
            '': {
              templateUrl: 'app/main/main.html',
              controller: 'MainController',
              controllerAs: 'main'
            'header': {
              templateUrl: 'app/main/header.html',
              controller: 'HeaderController',
              controllerAs: 'header'
            'footer': {
              templateUrl: 'app/main/footer.html'

reference link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download