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我可以手動切換它,但它不是一個重點。