【问题标题】:Expression 'undefined' in attribute 'materialSwitch' used with directive '{2}' is non-assignable! (Angular)与指令“{2}”一起使用的属性“materialSwitch”中的表达式“未定义”是不可赋值的! (角度)
【发布时间】: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


    【解决方案1】:

    已修复 - 在模板上我没有在 material-switch="" 之后附加模型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 2021-05-07
      相关资源
      最近更新 更多