colmol29 colmol29 - 5 months ago 21
AngularJS Question

Styling an angular directive on ng-click with isolate scope

I have two directives that should both use isolate scopes,

<outer-box>
and
<flag>
. When I click on the
<flag>
directive, I want to change the background color of the other directive. Before importing my code into JSFiddle, I also had it working so that by default, a placeholder image appears in the flag directive, but once you click on that image, the country flag appears instead.

Can someone help with the styling a separate directive on ng-click?

Here's my code: https://jsfiddle.net/nLduw6xw/
(My countries data isn't working in JSFiddle for some reason)

Answer

You can do it with requiring one directive from another. In this example you can require outer-box to be a parent of flag. With this you have the access to required directive controller ( 4th parameter in link function), so you can call a method to set class on element.

Working JSFiddle : https://jsfiddle.net/2atnxhgy/