-2

I am not sure whether I can do like this or there is a better way. I need someone to guide me.

I created two template using directive (both directives in the same page). Let say

  • directiveVideo for display videos
  • directivePhoto for display photos

Then I have a controller. this controller requests two different data, videos and photos. My question is, how can I pass the video data to display in directiveVideo and photo data to directivePhoto

vzhen
  • 11,137
  • 13
  • 56
  • 87

1 Answers1

2

Your question is incredibly vague, so I'll give an equally vague answer. If you want something more specific, you'll need to edit your question to include some code - preferably in a Plunker.

If your controller declares two scope vars, videos and photos, then you can simply pass those as attributes to your directives:

<div photos="photos"></div>
<div videos="videos"></div>

And you can read this in from your directive. Assuming you have an isolate scope:

scope: { photos: '=' }

Otherwise:

scope: true,
link: function ( scope, element, attrs ) {
  attrs.$observe( 'photos', function ( val ) {
    $scope.photos = val;
  });
}

And your template can access it however it needs to:

<ul>
  <li ng-repeat="photo in photos"><img ng-src="{{photo.url}}" /></li>
</ul>
Josh David Miller
  • 120,525
  • 16
  • 127
  • 95
  • Sorry for my question because I haven't try it out myself so I quite blur about it. I will requestion or update it again after i try. – vzhen Apr 07 '13 at 12:35