0
我正在使用angular 1.4.x和Bluradmin模板。问题是渲染DOM期间bootstrapswitch custom directive在ngModel中更改后更新bootstrapswitch
(function() {
'use strict';
angular.module('BlurAdmin.pages.form')
.directive('switch', switchDirective);
/** @ngInject */
function switchDirective($timeout) {
return {
restrict: 'EA',
replace: true,
scope: {
ngModel: '='
},
template: function(el, attrs) {
return '<div class="switch-container ' + (attrs.color || '') + '"><input type="checkbox" ng-model="ngModel"></div>';
},
link: function (scope, elem, attr) {
$timeout(function(){
var input = $(elem).find('input');
input.bootstrapSwitch({
size: 'small',
onColor: attr.color
});
input.on('switchChange.bootstrapSwitch', function(event, state) {
scope.ngModel = state;
scope.$apply();
});
}, 2000);
}
};
}
})();
只加载正确一旦连接,然后在ngModel更改后,它不会刷新。我怎样才能实现它? btw我可以手动切换它,但它不是一个重点。