이 상태를 초기화하지 않는 bootstrap switch 초기화부트 스트랩 내가 '
<span style="margin-right: 5px;">{{accessory.name}} </span>
<input type="checkbox" name="accessory{{accessory.id}}"
data-ng-model="accessory.value" data-ng-attr-id="{{accessory.id}}"
data-ng-attr-topic="{{accessory.topic}}" bootstrap-switch>
ng-model
에 문제가 있음을했습니다, 그것은 항상 false입니다 각 초기화를 switchand. ng-checked="{{accessory.value}}"
으로 시도했지만 아무 것도 변경되지 않았습니다. checked
또는 checked="checked"
을 사용하면 문제가 없습니다. 조언이 있으십니까?
app.directive('bootstrapSwitch',
['$http',
function($http) {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
element.bootstrapSwitch({size: "small", onColor:"success", offColor:"danger"});
//ngModel.$setViewValue(false); //set start status to false
element.on('switchChange.bootstrapSwitch', function(event, state) {
if (ngModel) {
scope.$apply(function() {
ngModel.$setViewValue(state);
});
}
});
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
if (newValue!= oldValue){
$http({
method: 'PUT',
url: '/reservations/' + document.getElementById("hiddenIdReservation").value + '/accessories/'+ element[0].attributes.id.value,
params: {topic: element[0].attributes.topic.value, value: newValue}
}).then(function successCallback(response) {
if (typeof response.data.success == 'undefined'){
window.location.href = "/500";
}else if (response.data.success==true){
if (newValue) {
element.bootstrapSwitch('state', true, true);
} else {
element.bootstrapSwitch('state', false, true);
}
}else if (response.data.success==false)
notifyMessage(response.data.result, 'error');
}, function errorCallback(response) {
window.location.href = "/500";
});
}
});
}
};
}
]
);
ngModel.$setViewValue(false);
값의 코멘트와 진정한되지만 스위치 오프에 여전히 :
이 부트 스트랩 스위치에 대한 지침이다.
이렇게하기 위해 어떤 부트 스트랩 스위치 라이브러리를 사용하고 있습니까? –
http://bootstrapswitch.com/ 메인 포스트에 명시된대로 – luca
jquery 플러그인입니다. 사용하고있는'bootstrap-switch' 각 지시자의 소스를 원합니다. –