Jay Shukla Jay Shukla - 1 year ago 98
Javascript Question

Passing ng-repeat local object to directive controller is not working

I'm trying to pass my

local object to directive. I need to access the data from that object inside my directive controller. I'm confused about
iso-lated scope
and controller scope. Why it's not working.

Demo Fiddle about what I'm trying


<div ng-app="my-app" ng-controller="MainController">

<div ng-repeat="document in documents">


module.directive('nameRow', function() {
return {
restrict: 'E',
replace: true,
scope: {
documentElement : '=document',

controller: function($scope) {
' <ul>' +
' <li>' +
' <a>' +
' {{documentElement.targetPrice}}' +
' </a>' +
' </li>' +
' </ul>'

I just want to understand why it's not working. I don't want to do with any alternatives like accessing this in link function etc.

Answer Source

You used alias for attribute =document, You attribute should be document instead of document-element.

<div ng-repeat="document in documents">

Other way would be you could remove an alias of attribute in isolated property declaration.

scope: {
   documentElement : '=', //just have `=` instead of `=document`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download