我正在使用Angular 1.3和Angular 1.3并实现了一个材质切换按钮,基本上有一个开/关'看看我将用来返回一个真/假布尔值。
当我点击下面的div时,它会返回以下错误:
Expression 'undefined' in attribute 'materialSwitch' used with directive '{2}' is non-assignable!
//我的模板
<div class="user-material-switch" material-switch=""></div>
//我的指令
abcdDirectives.directive('materialSwitch', function() {
return {
restrict: 'A',
scope: {
'model': '=',
'switchDisabled' : '=',
'switchLabel': '@'
},
template: '<div class="material-switch" ng-click="switch()" ng-class="{active: model, disabled: switchDisabled}"><div class="switch-back"></div><div class="switch-front"></div></div>',
link : function(scope, element, attrs) {
scope.switch = function() {
if (scope.switchDisabled) {
return;
}
scope.model = !!!scope.model;
}
}
}
});
任何想法我做错了什么?
答案 0 :(得分:0)
已修复 - 在模板上我没有在材料切换后附加模型=&#34;&#34;