$ scopeからこのようなカスタムディレクティブに属性を渡すことができる必要がありますか?
<div ng-repeat="ratable in ratables">
<div>How much do you like {{ratable.name}}?</div>
<!-- CONFUSED - First element does not work, second element does -->
<rating currentRatingValue="{{ratable.currentvalue}}" maxRatingValue="10"></rating>
</div>
ハードワイヤードの「10」はディレクティブに問題なく通過しますが、{{ratable.currentvalue}}を渡そうとしたときの文字列補間は発生しないようです。私は明らかに間違ったことをしていますか?
http://jsfiddle.net/ADukg/2168/
var myApp = angular.module('myApp',[])
.directive("rating", function () {
return {
restrict: "E",
scope: {},
template: "<div class='rating'>Current rating: {{currentratingvalue}} out of {{maxratingvalue}}</div>",
link: function (scope, element, attributes) {
console.log(attributes.currentratingvalue); // Does not work but seems like it should
console.log(attributes.maxratingvalue); // Does work
}
};
});
function MyCtrl($scope) {
$scope.name = 'Superhero';
$scope.ratables = [
{ name: "sledding", currentvalue: 3, maxvalue: 5 },
{ name: "water skiing", currentvalue: 7, maxvalue: 10 },
{ name: "whitewater rafting", currentvalue: null, maxvalue: 10 }
];
}
<div>
<div ng-controller="MyCtrl">
Hello, {{name}}!
<div ng-repeat="ratable in ratables">
<div>How much do you like {{ratable.name}}?</div>
<!-- CONFUSED - First element does not work, second element does -->
<rating currentRatingValue="{{ratable.currentvalue}}" maxRatingValue="10"></rating>
</div>
</div>
</div>