I have been playing with AngularJS for only a few days and came up with something that I could not solve yet.
Each contact can have several addresses and phone numbers. Since inserting and editing a contact will require almost the same functionality at the user interface level, I decided to create a directive such as following addresses and phones:
Address:
(function () { var app = angular.module("AddressesEditorModule", []); app.directive("addressesEditor", function () { return { restrict: "E", templateUrl: "/addressesEditorTemplate.html", controller: function ($scope) { this.addresses = [
Telephone:
(function () { var app = angular.module("PhonesEditorModule", []); app.directive("phonesEditor", function () { return { restrict: "E", templateUrl: "/phonesEditorTemplate.html", controller: function ($scope) { this.phones = [
I skipped the methods declared inside the directives to work with the addresses and phones variables.
Both directives are also used in HTML:
<div ng-app="ContactModule"> <div ng-controller="InsertController as insertCtrlr"> <addresses-editor></addresses-editor> <phones-editor></phones-editor> </div> </div>
This work is exactly as I expected, with correctly recorded phones and addresses.
Now, what I want to do is get the phones and addresses inside the directive and send them to the server for writing to the contact in the database.
I know how to do AJAX, but I have no idea how to exchange data between directives and InsertController (variables with the data I want: this.addresses from the addressesEditor directive and this.phones from the phonesEditor directive).
How can i do this?