Throughout my app, there is a consistent functionality where users can input a title and link.
I decided to create a directive for this. However, the directive needs to be utilized in various controller contexts.
For instance, in the /contracts view, the controller is ContractsController, which sends an API request to save a contract upon submission.
On the other hand, in the /meeting-notes view, the controller is MeetingNotesController, responsible for saving meeting notes against a client through a different endpoint.
Below is the current state of my directive: app.js
.directive('myprefixLinkAttachment', function($timeout) {
return {
restrict: 'A',
templateUrl: '../partials/directives/link-attachment.html',
scope: {},
link: function link(scope, element, attrs) {
$timeout(function() {
console.log(scope.$parent);
console.log(scope.title);
}, 5000);
}
}
})
The timeout successfully returns the correct value - I used it to test if I could obtain the value.
link-attachment.html
<md-input-container class="md-block" md-no-float flex="100" flex-gt-xs="66">
<input ng-model="title" placeholder="Title...">
</md-input-container>
<md-input-container class="md-block" flex="100" flex-gt-xs="33">
<input ng-model="link" placeholder="Title..." ng-keypress="CtrlNameHere.save($event)">
</md-input-container>
I invoke the directive within the ContractsController, but this may vary:
<div layout="column" layout-gt-xs="row" class="new-entry-line" myprefix-link-attachment>
To sum up, I aim to freely implement the directive while ensuring that the appropriate controller is called to handle the CtrlNameHere.save() method.