I've encountered similar questions to mine that have been addressed, but I believe my scenario is unique. I began with the sample code available on this page for a basic app featuring a sliding menu integrated with Google Maps.
My current project involves creating a prototype allowing users to submit new items, which are then added to a list of pending submissions and displayed on the map. Currently, I am focused on enabling users to create items and automatically updating the list of pending submissions. I have implemented a simple form for creating new items:
<ons-page>
<ons-toolbar fixed-style ng-controller="SlidingMenuController">
<div class="left">
<ons-toolbar-button ng-click="slidingMenu.toggleMenu()"><ons-icon icon="bars"></ons-icon></ons-toolbar-button>
</div>
<div class="center">New Submission</div>
</ons-toolbar>
<ons-row style="margin-top: 10px; text-align: center;">
<ons-col ng-controller="NewSubmissionController">
<p style="font-size: 12px;">Please provide a brief description and material details of your find.</p>
<textarea style="width: 97%;" id="subDescrText" class="textarea" rows="4" placeholder="Type your description here..." value="" ng-model="subDescription"></textarea>
<ons-button style="margin-top: 24px;" ng-click="doStore()">
Store
</ons-button>
</ons-col>
</ons-row>
</ons-page>
Another page has been set up to display the created submissions:
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="slidingMenu.toggleMenu()"><ons-icon icon="bars"></ons-icon></ons-toolbar-button>
</div>
<div class="center">Pending Submissions</div>
</ons-toolbar>
<div style="text-align: center;">
<ons-list id="pendingList" var="aPendingList" ng-controller="PendingListController">
<ons-list-item ng-repeat="pi in pendingItems">
<p>{{pi.description}}</p>
<span>{{pi.material}}</span>
</ons-list-item>
</ons-list>
</div>
<p style="margin-top: 12px; text-align: center; width: 100%;" >
<ons-button ng-click="">
Upload All
</ons-button>
</p>
</ons-page>
The necessary controllers have also been added:
app.controller('NewSubmissionController', function($scope) {
$scope.selMat;
$scope.subDescription;
$scope.doStore = function() {
alert('In NewSubmissionController.doStore() - Selected material: ' + $scope.selMat + '\nDescription: ' + $scope.subDescription);
var newPI = new SubmissionItem($scope.selMat, $scope.subDescription, '');
$scope.$emit('newPI', newPI);
slidingMenu.setMainPage('pendingList.html', {closeMenu: true});
};
});
// Controller for Pending List
app.controller('PendingListController', function($scope) {
$scope.pendingItems = [];
$scope.$on('newSubEvent', function(e, subMat, descr) {
alert('In PendingListController, event newSubEvent - Submitted material: ' + subMat + '\nDescription: ' + descr);
});
$scope.addPendingItem = function(newPi) {
alert('In PendingListController.addPendingItem() - ' + newPi);
$scope.pendingItems.unshift(newPi);
// Code to update the list of pending submissions...
};
});
In my attempt to utilize the event system based on suggestions, it appears ineffective as the two controllers are not linked hierarchically. Even placing PendingListController within NewSubmissionController proved futile likely due to both being part of separate views.
What would be the most efficient solution to trigger PendingListController.addPendingItem() from NewSubmissionController?