0

my plunker : http://plnkr.co/edit/5bRMwOJhwW8RQCfnfkK6?p=preview

in main.html line 35 I declared

<li ng-repeat="friend in tabFriends">
{{friend[0].name}}
</li>

to try to echo out friends' name but it returned blank. The data is in data.js. The todo list item work well, I wonder why.

1 Answers1

0

The problem lies in the value your passing to your taskform directive. You are only passing tab.tasks where as tab.tabFriends is a different array of objects.

You really need to reconstruct how you directive is made. You are assigning $scope.tabs inside your directive where there is no guarantee that where it will be used will have that value. You should divide your directive in to a controller: function() and a linker: function() the latter being for the initialization of the directive.

If you want to find a really awesome example of directives with controllers and linker functions look in the angularjs javascript itself for the ng-model directive. It will give you a really good idea how it should be structured!

3066d0
  • 1,853
  • 1
  • 14
  • 18
  • You should divide your directive in to a controller: function() and a linker: function() the latter being for the initialization of the directive. I don't get this – user3519144 Apr 12 '14 at 04:43
  • This post explains it more in depth :) http://stackoverflow.com/questions/15676614/directive-link-vs-compile-vs-controller – 3066d0 Apr 12 '14 at 04:54
  • is there any shorter fix to my problem? what I change the directive to be like this : – user3519144 Apr 12 '14 at 05:03