0

This will explain the question a lot better.

I have a page that uses the vendorExperienceCtrl controller. I get data and this ng-repeat prints out little html templates as "current available tasks" that the user can perform.

<div ng-repeat="task in tasks" class="task">
  <ng-include src="getTaskItemTemplate(task.app_task_type_id);"></ng-include>
</div>

For example one of the template is a post to twitter button with the following code.

{{task.id}}
<button ng-controller="twitterController" ng-click="postTweet(task.id)">
    <img src="img/twitter-icon.png" alt=""><br>
    Tweet
</button>

This button uses the twitterController to call the postTweet function. I included {{task.id}} above because that correctly displays the right id. The postTweet() function needs that task.id to process whether or not the task had been done already or not.

However in the postTweet() function the value of that task.id is undefined. Is there a way to pass that task.id, clearly controlled by a different controller into that postTweet() function of another controller?

tbondt
  • 235
  • 1
  • 3
  • 10

1 Answers1

1

I think that $parent.task.id would work in that case. I do recommend to use services to handle your data though. Also this might be relevant to you: What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

Community
  • 1
  • 1
Alex C
  • 1,334
  • 2
  • 18
  • 41