javascript - passing defined object to another custom directive angularjs -


So I have these custom instructions that you can see below.

MyDirective ('MyDirective', function (testService) {return {restrict: 'EA', link: function (scope, element, attr) {// object var object = new Object () is defined; testService.setObject (object);}}}); MyApp.directive ('mySecondDirective', function (testService) {return: {ECA, link: function (radius, element, et)) // Call variable from previous custom-direct console.log (testService.getobject ()); - & gt; Always back uncredited}}});

And this is html structure where I used the above instructions.

  & lt; My-directive & gt; & Lt; / My-directive & gt; & Lt; My-second instructions & gt; & Lt; / My-second instructions & gt;  

There I want to get rid of object containing the new item () from the previous custom command, but it is always a Undefined I wonder how can I do this without using Needs and a separate scope . Can you help me?

Update I create a service to provide the facility to set and retract the object and apparently returned the undefined because I have created custom directives I

  & lt; My-second-directive & gt; & Lt; / My-second instructions & gt; & Lt; My-directions & gt; & Lt; / My-directions & gt;  

and this service is

  define (['services / services'], function (services) {'strict use'; services.factory ('TestService', [function] {var me = this} var testObject = ''; return {setObject: function} {me.testObject = object;}, getObject: function () {me.testObject return}} }];);});  

The thing is that I actually set up html markup as I've already mentioned

   

So can you give me some advice on how I should do this?

Note that passing things actually works like using the services because it will be easy to build the house. The question is how can I access this object from another directive, even though the start of the object (set the object) I set the object defined in html markup, as it is the last place in html?

UPDATE is that I have created this question for you to understand yourself

You can get it by firing a custom event and then can listen to it in another instruction. Here's an updated planer:

Broadcast the event with the first instruction:

  app.directive ('myDirective', function (testService)) {return {restricted} : 'EA', link: function (scope, elm, ether) {var object = {}; TestService.setObject (object); Console.log ('setting object'); Scope $ Broadcast ('objectSet');}}});  

... and then listen to it on another:

  app.directive ('mySecondDirective', function (testService) {return {restrict: 'EA ', Link: function (scope, elm, atr) {$ (' object set ', function) (console.log (' retrieve item ', testService.getObject ());})}}}}};  

You can also pass data with the event, if you want to exclude specific part of the data that is taken by the second instruction.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -