Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Angular service to provide data
    primarykey
    data
    text
    <p>I am building a SPA where one can open a dialog-window that contains a list of options. The user can pick an option, then said option should be attached to the main-view of the application (As in: pick <em>A</em> from a dialog, then attach <em>A</em> to an <code>&lt;ul&gt;</code> on the frontpage).</p> <p>The dialog is independet and has its own module and controller:</p> <pre><code>var AdviceList = angular.module('adviceList', []); AdviceList.controller('AdviceListCtrl',function($scope,$http){ //... }); AdviceList.provider('$adviceList',function(){ this.$get = function ($rootScope,$document,$compile,$http){ function AdviceList(){ // ... } AdviceList.prototype.open = function(){ // ... } }) </code></pre> <p>I do not understand how to share the list of chosen options with the rest of my application.</p> <p>My approach was to create an array <code>activeOptions</code> and attach it to the controller's scope, but in that case, it will be out of reach for the provider:</p> <pre><code>AdviceList.controller('AdviceListCtrl',function($scope,$http){ $scope.activeOptions = []; $scope.addAdvice = function(){ $scope.activeOptions.push(); // push the chosen option } }); AdviceList.provider('$adviceList',function(){ this.$get = function ($rootScope,$document,$compile,$http){ return{ AdviceList: function(){ return new AdviceList(); }, getActive: function(){ // no access to the controllers scope here } } } }) </code></pre> <p>What is the recommended, best practice way of sharing data application wide and implement such functionality as i need?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload