2013-04-18 1 views
1

컨트롤러에서 stuff라는 속성의 JSON 배열을 가져 오는 지시문이 있습니다. 그 부분은 잘 작동합니다. 내가 지금하고있는 일은 배열의 길이를 사용하고 TR과 TD 요소를 반복하여 멋지게 형식화 된 테이블을 만들 수있는 링크 함수를 만드는 것이다. Stack에서이 좋은 예가 발견되었지만 문제는 링크 기능에서 내 stuff 속성을 벗어날 수 없다는 것입니다. 나는 정의되지 않는다.AngularJS : 링크 함수의 범위에서 요소를 가져 오는 방법

컨트롤러 :

function itemControl($http, $scope) { 
    $http.get('doc/products.json').success(function (prodata) { 
    $scope.data = prodata; 
    }); 
} 

지침

app.directive("showcase", function() { 
    return { 
    restrict: "A", 
    template: '<table>' + 
       '<colgroup span="2"></colgroup>' + 
       '<tr ng-repeat="items in stuff">' + 
       '<td>' + 
       '<a ng-href="{{items.SRC}}" Title="{{items.name}}" colorbox>' + 
       '<img ng-src="{{items.SRC}}"></a>' + 
       '</td></tr></table>', 
    scope: { 
     stuff: "=" 
    }, 
    link: function (scope) { 
     alert(scope.stuff); 
    } 

    }; 
}); 

HTML

<div ng-controller="itemControl"> 
    <div showcase stuff="data"></div> 
</div> 
+0

당신이 그것을 쉽게하는 jsfiddle을 게시/plunkr 수 있다면 도움이 될 것입니다 도움을 줄 다른 사람들. 그 동안 http://stackoverflow.com/questions/15253471/isolate-scope-attributes-defined-with-are-undefined-disappear-in-directives-l –

+0

을 살펴 보겠습니다. 나는이 바이올린을 만들려고 노력했지만 아무 결과도 얻지 못했고, 나는 항상 필자가 왜 그런지 모릅니다. – richbai90

답변

관련 문제