나는 이것을 알기 위해 볼 수 없다 ... 나는 바보 같은 짓을하는 경우에 너무 미안하다.지시어 내에서 랜덤 ng-show
지시어의 일부를 ng-show를 사용하여 무작위로 표시하려고합니다.
HTML :
<div ng-controller="MyCtrl">
<div ng-repeat="color in colors">
<my-directive color="color"></my-directive>
</div>
</div>
컨트롤러 :
function MyCtrl($scope) {
$scope.colors = [
{color: "red", stuff: "1"},
{color: "blue", stuff: "2"},
{color: "yellow", stuff: "3"}
];
}
지침 :
myApp.directive('myDirective', function() {
return {
restrict: 'EA',
scope: {
color: '=',
showText: '@'
},
template: 'test <p ng-show="showText">{{color.color}} {{color.stuff}}</p>',
controller: function ($scope, $element) {
$scope.showText = Math.random() < 0.5;
}
}
});
<p>...</p>
보여줍니다하지, 왜? 당신이 (@
) 텍스트 범위 속성 showText
구속력을 가지고 있기 때문에입니다
http://jsfiddle.net/oxr4c9ub/2/
@BhojendraSah 내 무작위. :) – PSL