2016-04-26 38 views
2

我刚刚开始角度转换。我想传递一个对象数组和我想要在迭代中显示的对象的特定属性。 我试图创建将下面使用的指令:如何在转发器内使用角度范围变量

HTML代码

<div ng-controller="MyCtrl"> 
    <pass-object objects="objs" prop="'value'"></pass-object> 
</div> 

指令代码:

var myApp = angular.module('myApp',[]) 
    .controller('MyCtrl', function ($scope) { 
     $scope.objs = [{ value: "hello" },{ value: "world" }]; 
    }) 
    .directive('passObject', function() { 
     return { 
      restrict: 'E', 
      scope: { objects: '=', prop: '@' }, 
      template: '<span data-ng-repeat="obj in objects">{{obj[prop]}}</span>' 
     }; 
    }); 

工作因为道具价值不能像这样评价。因为道具应该在重复使用之前编译。

外重复我可以显示属性作为字符串

<span>{{prop}}</span> 

如何评估像重复内的值{{OBJ [“值”]}}

回答