【发布时间】:2017-06-26 12:29:52
【问题描述】:
我在 Angular 1.3 中使用 Angular Material,并实现了一个材质切换按钮,该按钮基本上具有“开/关”外观,我将使用它来返回一个真/假布尔值。
当我点击下面的 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;
}
}
}
});
任何想法我做错了什么?
【问题讨论】:
标签: javascript angularjs angular-material