angularjs - What should i do to put data from the controller in a directive? -


i've scenario:

1) user clicks on link , request sent (from controller) backend create db record.

2) response returned promise in controller , able see data db.

3) link clicked in #1 opens directive (element directive btw) displays popup window.

4) controller , directive not related, need show data in popup (opened directive).

i'm new ajs , knowledge smattering. should use service/rootscope? send data promise directive.

it sounds main question how data directive. can think of 2 ways (there more).

you can use directive's isolate scope pass in information controller. have few options binding scope (see scope section of $compile). = two-way binding or & expression binding &. might like

app.directive('mydirective', [     function() {          restrict: 'e',          templateurl: 'some template url',          scope: {              databaserow: '='          }     } ]) 

which used in html

<my-directive database-row="controllerresult"></my-directive> 

you can create , inject service directive, , move db logic directive. have controller broadcast event or change variable trigger directive, or have visible element within directive respond mouse click.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -