Passing a data object to a directive inside ng-repeat

I am having problems passing a data object from ng-repeat to an internal directive. You can find it here: JSBin

In the Chrome developer tools, I see that the data object is not defined, but I cannot understand why. I pass it into a directive and then bind it to the area.

I thought that for each ng-repeat loop an assembly is created and the internal directive is parsed. Right?

In addition, I want to pass the data object into a directive and get access to all the data there and install listeners on this object. Is it possible?

+4
source share
2 answers

This is a snippet of your directory code:

return {
  restrict: 'E',
  scope: {
    data: "="
  },
  link: function(scope, element, attrs) {
    // here is the problem, data is really undefined
    console.log(data);

, , - undefined data. scope.data. , :

link: function(scope, element, attrs) {
   console.log(scope.data); // here scope.data

plunker

+4

scope: {
    data: "="
}

scope.data. , , .

+1

Source: https://habr.com/ru/post/1545404/


All Articles