NPanda NPanda - 1 year ago 87
AngularJS Question

MVC Spring AngularJS Directive and Controller

I am trying to get a MVC with Spring and Angular JS and it is currently working [well actually it just calls the index.html so yeah].
The thing is, when I am in my index.html, I simply put a ng-include to another html file like this :

<div ng-include="'folder/view.html'"></div>

The thing is... I would like to call the directive of the file first, which will call the controller right after and then call the view but I do not know how to proceed.

Here is my directive :

'use strict';

.directive('view', function() {

return {
restrict: 'AE',
templateUrl: "folder/view.html",
controller : "viewController",
scope: {
state: "@",


And here is my controller :

'use strict';
.controller('viewController', function ($scope) {

// Do some stuff


But none of these two are called. Can someone help me please ?
I do not know if I am specific enough, I'd like to apologize in advance.

Plunker :

Thank you !

Answer Source

Well, you of course need to load the JS files defining the controller and the directive:

<script src="script.js"></script>
<script src="viewController.js"></script>
<script src="viewDirective.js"></script>

Then you need to actually use the directive in your template:


And finally, since the view.html is not in a folder, you need to use the right path.

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