0

Hi everybody I am new to angular and still trying to get the basics down. I have a view that has two controllers controlling two different pieces of that view:

<div class="row" ng-app="appDiary">
    <div ng-controller="entryController as vm">
       ....
    </div>
    <div ng-controller="otherController as vm">
       ....
    </div>
<div>

entryController.js / otherController.js:

angular.module("appDiary").controller("entryController", entryController);

function entryController($scope, $http, $filter, service) {
    ...functionality here...
}

Basically the view html has gotten long and I want to break it up into templates. I tried searching around and using the ngRoute.

angular.module('appDiary', ['simpleControls', 'chart.js', 'ngRoute']);
        .config(function ($routeProvider) {
            $routeProvider.when("/", { 
               controller: "entryController", "otherController" // Want both controllers here
               controllerAs: vm,
               templateUrl: "/views/entry.html", "/views/other.html"
            });
        }); 

How do I get Angular to map two controllers/templates to one route? Is there a better way to do this? I tried using some suggestions from Routing in angularjs for mutliple controllers? and couldn't get anything working. Thank you!

Community
  • 1
  • 1
John Doe
  • 205
  • 6
  • 17
  • Better use ``directives`` if you want break down long html views. – Sameer K Mar 09 '16 at 07:15
  • You could use a single template using ng-include to include the two smaller templates, or using two directives. Or use ui-router which has support for multiple named views. – JB Nizet Mar 09 '16 at 07:16

0 Answers0