javascript - AngularJS - Child directive uses same data as parent. How to share? -


i have child directive requires same data of parent pages use it.

what best way share data?

should child directive make same api call parent?

or should parent send data directive via attributes?

i think depends.

if parent , child directive ever going re-used separately (meaning use 1 without other) want use attributes api pass data child directive.

if going used together, 1 of following:

  • use attributes pass value
  • remove isolate scope child , have child scope inherit values parent scope. hate when people this, each own.
  • have service caches values, , both call service , same values back.
  • you have parent scope broadcast data down it's children using scope eventing system.

all of these work. need discuss team , think should adopt regular pattern. after that, implement away.

good luck!


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -