I'm trying to create a directive 'pForm' so that I can easily create instances of forms inside of html pages via tags:
<p-form></p-form>
Each form will consist of the template: templates/form.html connected to an instance of the controller 'form' in the module 'forms'.
With that said, here's how I tried to approach it:
Main Module (in dependencies - forms module):
angular.module('mainModule', ['forms'])
.controller('MainController', ['$scope', function($scope) {
}]);
Forms Module:
angular.module("forms", [])
.controller("form", ['$scope', function($scope) {
alert("init");
}])
.directive('pForm', function() {alert('directive');
return {scope: {data: '=data'}, templateUrl: 'templates/form.html'};
});
The html file inits ng-app="mainModule", and I place in the html's body the following:
<p-form></p-form>
the alert 'directive' works, but the controller is not instantiated (no "init" alert).
I imagine I got the concept of directives somewhat backwards. Please let me know what you think.