簡體   English   中英

與指令“ {2}”一起使用的屬性“ materialSwitch”中的表達式“ undefined”是不可分配的! (角)

[英]Expression 'undefined' in attribute 'materialSwitch' used with directive '{2}' is non-assignable! (Angular)

我在Angular 1.3中使用了Angular Material,並實現了一個材質切換按鈕,該按鈕基本上具有“ on / off”外觀,我將使用它來返回真/假布爾值。

當我單擊下面的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;
        }
    }
 }
});

有任何想法我做錯了嗎?

固定-在模板上,在material-switch =“”之后我沒有附加模型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM