각도 명령을 만들었지 만 ng-repeat
으로 실행되지 않습니다. 나는 이유를 모른다. 두 번째 지시문이 성공적으로 실행됩니다.ng-repeat로 작동하지 않는 각도 명령
자바 스크립트 :
angular.module('myApp',[])
.controller('Ctrl',['$scope', function ($scope) {
$scope.vvv = [];
$scope.bbb = [];
$scope.testdatas = [{text : 0},{text : 1},{text : 2},{text : 3}]
}])
.directive('wstCheckbox', function() {
return {
restrict:'EA',
replace:true,
template:'<div ng-transclude></div>',
scope:{
modelname : '=' //ths is the model
},
transclude:true,
link : function (scope,element,attrs) {
console.log(element)
$(element).find('input[type=checkbox]').on('change', function() {
scope.modelname = [];
scope.$apply(function() {
$(element).find('input[type=checkbox]:checked').each(function() {
scope.modelname.push($(this).val());
})
})
})
}
}
})
HTML :
<div>
<wst-checkbox modelname="vvv">
<div>{{vvv}}</div>
<input type="checkbox" name="test" value="data.text" ng-repeat="data in testdatas"/>
</wst-checkbox>
<wst-checkbox modelname="bbb">
<div>{{bbb}}</div>
<input type="checkbox" name="test" value="0" id="4"/><label for="4">index 0</label>
<input type="checkbox" name="test" value="1" id="5"/><label for="5">index 1</label>
<input type="checkbox" name="test" value="2" id="6"/><label for="6">index 2</label>
<input type="checkbox" name="test" value="3" id="7"/><label for="7">index 3</label>
</wst-checkbox>
</div>
stackoverflow에 오신 것을 환영합니다. 가독성을 높이기 위해 코드 샘플을 재구성하고 가장 관련성이 높은 부분까지 끈 다음 게시에 명확한 질문이 포함되어 있는지 확인하십시오 – Sprottenwels