0

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';
angular.module('tmp')

.directive('view', function() {

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

    }
});

And here is my controller :

'use strict';
angular.module('tmp')
    .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 : https://plnkr.co/edit/EFScNxJV7qG9cTSACDZ2?p=preview

Thank you !

NPanda
  • 41
  • 9

1 Answers1

0

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:

<body>
  <view></view>
</body>

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

https://plnkr.co/edit/DygHtWNMtWTG7hy4vBUb?p=preview

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255