JavaScript share data between sibling directives share data between components angular,share data between docker containers,

Currently, I am facing one issue related to angularjs directive. I want to send outlet object from directive1 to directive2. Both directives having same controller scope. I tried with emitting event from directive1 to controller, broadcasting that event from controller to directive2 and listening to that event on directive2. but that is not working.

Directive1:

angular.module('moduleName')
.directive('directive1', function() {
    return {
        restrict: 'E',
        templateUrl: 'directive1.html',
        scope: false,
        link: function(scope) {
            scope.selectOutlet = function(outlet) {
                scope.order.entityId = outlet.id;
                scope.navigation.currentTab = 'right';
            };
        }
    };

Here, in directive1, scope.selectOutlet() setting outletId to scope.order.entityId. I want to move/set that line to directive2 save function.

Directive2:

angular.module('moduleName')
.directive('directive2', function(config, $rootScope, $state) {
    return {
        restrict: 'E',
        templateUrl: 'directive2.html',
        scope: false,
        link: function(scope) {
            scope.save = function() {
                // Save functionality  
                // scope.order.entityId = outlet.id; This is what i want to do
            };
        }
    };
});

});

Any help.

Answer:1

you can use a factory or a service. Inject that factory into your directive. Now when you are trying set the data in function written into factory. `app.factory('shared',function(){ var obj ={};

obj.setData = function(){
// call this function from directive 1.
 }
 return obj;
})`

So if you include this factory into your directives you will get the data in 2 directives.

I will try to make some jsfiddle or plunker. If it is not clear.

Answer:2

In the following code, the $compile is not working. I have an item, I am adding this item to scope, so that I can compile this and get an html. $http({ method: 'GET', url :...

In the following code, the $compile is not working. I have an item, I am adding this item to scope, so that I can compile this and get an html. $http({ method: 'GET', url :...

  1. angularjs $compile not working
  2. angularjs works compile
  3. angularjs directive compile not working
  4. angularjs compile ng-click not working

I created a new vue project with the CLI and want to deploy it. Based on this documentation https://router.vuejs.org/guide/essentials/history-mode.html#html5-history-mode I added the history mode to ...

I created a new vue project with the CLI and want to deploy it. Based on this documentation https://router.vuejs.org/guide/essentials/history-mode.html#html5-history-mode I added the history mode to ...

I want to trying adding class using javascript, I know there is a lot of topic about this in stackoverflow but some of them is too complicated for me to understand, let say I have this simple code ...

I want to trying adding class using javascript, I know there is a lot of topic about this in stackoverflow but some of them is too complicated for me to understand, let say I have this simple code ...

  1. class javascript use strict
  2. javascript class using function
  3. javascript class using prototype
  4. class using javascript
  5. class in javascript
  6. class in javascript example
  7. javascript class with functions
  8. javascript class with constructor
  9. javascript class with properties
  10. javascript class with methods
  11. javascript class with multiple constructors
  12. javascript class with static methods
  13. javascript class with async function
  14. javascript class with array
  15. javascript class with variables
  16. javascript class with parameters
  17. javascript class in html
  18. javascript class in namespace
  19. javascript class with array property
  20. javascript class with arrow function

I have two variables with JSON files. The first is a list of keys looks like this: keylist = ["key1","key2","key3"] The second one is generated from a database and looks like this: data = { "...

I have two variables with JSON files. The first is a list of keys looks like this: keylist = ["key1","key2","key3"] The second one is generated from a database and looks like this: data = { "...

  1. access array with pointer c++
  2. access array with pointer
  3. access array with key javascript
  4. access array with index php
  5. access array with python
  6. access array of objects javascript
  7. access array in javascript
  8. access array in php
  9. access array of objects
  10. access array in matlab
  11. access array from another class java
  12. access array of json objects javascript
  13. access array in jquery
  14. access array in json
  15. access array by index javascript
  16. access array in c
  17. access array in dictionary python
  18. access array in struct c
  19. access array in java
  20. access array in scala